Explain about link and definition section in C language

In C programming, the link section and definition section are parts of preprocessor directives that provide instructions to the compiler before the actual compilation begins.

The link section uses #include directives to include header files containing function declarations and definitions from system libraries. The definition section uses #define directives to create symbolic constants and macros.

Syntax

#include <header_file.h>    // Link section
#define CONSTANT_NAME value   // Definition section

Link Section

The link section tells the compiler which header files to include. This allows access to predefined functions and their prototypes −

#include <stdio.h>    // Standard input/output functions
#include <stdlib.h>   // Standard library functions
#include <math.h>     // Mathematical functions

Definition Section

The definition section creates symbolic constants using #define. These constants are replaced by their values during preprocessing −

#define PI 3.14159
#define MAX_SIZE 100
#define SQUARE(x) ((x) * (x))

Example: Circle Circumference Calculator

The following program demonstrates both link and definition sections −

#include <stdio.h>    // Link section
#define PI 3.14159    // Definition section

int main() {
    float radius, circumference;
    
    printf("Enter radius of circle: ");
    scanf("%f", &radius);
    
    circumference = 2 * PI * radius;
    
    printf("Circumference of circle = %.2f
", circumference); return 0; }
Enter radius of circle: 6
Circumference of circle = 37.70

Key Functions in stdio.h

Function Description
printf() Prints formatted output to screen
scanf() Reads formatted input from keyboard
getchar() Reads a character from keyboard
putchar() Writes a character to screen
fopen() Opens a file
fclose() Closes a file
fprintf() Writes formatted data to file
fscanf() Reads formatted data from file

Key Points

  • All preprocessor directives must start with the # symbol
  • Header files provide function prototypes and symbolic constants
  • Symbolic constants improve code readability and maintainability
  • Preprocessing happens before compilation

Conclusion

The link and definition sections are essential preprocessor directives in C. The link section includes necessary headers, while the definition section creates reusable constants, making programs more organized and efficient.

Updated on: 2026-03-15T13:21:55+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements