---
title: "Declaration vs definition; C program structure"
subject: "Computer Programming"
chapter: 3
key: "semester_1/computer_programming:declaration-definition-structure-of-c"
source: https://www.bctengineer.com/q/semester_1/computer_programming/declaration-definition-structure-of-c
site: BCT Engineering
---

# Declaration vs definition; C program structure

Computer Programming · Chapter 3: Introduction to ‘C’ programming

- Asked in: 2071 Shrawan, 4 marks
- Video: [Declaration vs. Definition of a variable in C](https://www.youtube.com/watch?v=TtJw4VUYsiM) — CodeVault
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/declaration-definition-structure-of-c
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-3

## Question

Differentiate between declaration and definition. Explain structure of C program with an appropriate example.

## Short answer

A declaration introduces a name/type without memory allocation (extern int counter; int add(int,int);), while a definition allocates memory or provides the function body (int counter=10; int add(int a,int b){...}). A C program typically consists of documentation, link, definition, global declaration, main(), and user-defined function sections.

## Answer

#### Declaration versus definition
| Declaration | Definition |
|---|---|
| Tells the compiler the name and type | Allocates memory or gives the function body |
| Can be repeated | Done only once |
| `extern int counter;`, `int add(int,int);` | `int counter = 10;`, `int add(int a,int b){...}` |

```c
#include <stdio.h>
extern int counter;          /* declaration only: no memory allocated here */
int add(int, int);           /* function declaration (prototype) */
int counter = 10;            /* definition: memory allocated, value given */
int main(void)
{
    int x;                   /* declaration that is also a definition */
    x = add(counter, 5);
    printf("%d\n", x);
    return 0;
}
int add(int a, int b)        /* function definition */
{
    return a + b;
}
```
Output: `15`

#### Structure of a C program
```text
 Documentation section   (comments about the program)
 Link section            (#include header files)
 Definition section      (#define constants/macros)
 Global declaration      (global variables, prototypes)
 main() function         (program starts here)
     declaration part
     executable part
 User-defined functions  (function definitions)
```

Example:
```c
/* Program to find area of a rectangle */      /* documentation section */
#include <stdio.h>                             /* link section */
#define UNIT "sq. units"                       /* definition section */
float area(float, float);                      /* global declaration */
int main(void)                                 /* main function */
{
    float l = 5, b = 3, a;
    a = area(l, b);
    printf("Area = %.1f %s\n", a, UNIT);
    return 0;
}
float area(float l, float b)                   /* user-defined function */
{
    return l * b;
}
```

Output:
```text
Area = 15.0 sq. units
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which pair is correct?
   A. extern int counter; is a definition
   B. int add(int,int); is a declaration (prototype)
   C. int counter = 10; is a declaration only
   D. A function body is a declaration
   Answer: B. A prototype declares; a function body defines. (Key point: Declaration vs definition)

2. In the structure of a C program, which section comes right after the link section?
   A. main() function
   B. User-defined functions
   C. Definition section
   D. Documentation section
   Answer: C. Order: documentation, link, definition, global declaration, main, user-defined functions. (Key point: Section order)

3. What goes in the link section?
   A. #include header files
   B. #define constants
   C. main()
   D. comments
   Answer: A. The link section holds #include lines. (Key point: Link section)

4. Where does program execution begin?
   A. First user-defined function
   B. main() function
   C. Documentation section
   D. Global declaration
   Answer: B. Execution starts at main(). (Key point: Where program starts)

## Related in Computer Programming

- [Variable declaration versus definition](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adeclaration-vs-definition) — Computer Programming, chapter 3
- [Structure of a FORTRAN program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-structure) — Computer Programming, chapter 11, asked 5×
- [Structure tag](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astructure-tag) — Computer Programming, chapter 8
- [Structure vs array; accessing members](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astructure-vs-array-access-members) — Computer Programming, chapter 8
- [Function definition; sum of two numbers](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afunction-definition-sum-two) — Computer Programming, chapter 6
- [Sending structure members to a function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astructure-members-to-function) — Computer Programming, chapter 8

## Related in other subjects

- [Appropriate vs inappropriate human resources](https://www.bctengineer.com/question.md?key=semester_7%2Forganization_and_management%3Ahuman-resources-appropriate) — Organization and Management, chapter 7
- [Org structure definition; line organization pros/cons](https://www.bctengineer.com/question.md?key=semester_7%2Forganization_and_management%3Aorg-structure-define-line) — Organization and Management, chapter 5
- [Flowchart vs structure chart](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aflowchart-vs-structure-chart) — Object Oriented Analysis and Design, chapter 1
- [Monolithic vs micro-kernel structure](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Amonolithic-vs-microkernel) — Operating System, chapter 1
