Wednesday, May 13, 2026

Structure of a C Program सी प्रोग्राम की संरचना

Every programming language follows a specific structure or format for writing programs. In C language, a program is divided into different sections, where each section performs a particular task. Understanding the structure of a C program is very important because it helps beginners learn how C programs are organized, compiled, and executed.

प्रत्येक प्रोग्रामिंग लैंग्वेज में प्रोग्राम लिखने का एक निश्चित प्रारूप या संरचना होती है। C language में भी program को विभिन्न sections में विभाजित किया जाता है, जहाँ प्रत्येक section एक विशेष कार्य करता है। C program की संरचना को समझना अत्यंत महत्वपूर्ण है क्योंकि इससे विद्यार्थियों को यह समझने में सहायता मिलती है कि C programs कैसे organize, compile तथा execute होते हैं।


Basic Structure of a C Program सी प्रोग्राम का मूल स्ट्रक्चर

A standard C program generally contains the following sections:

एक सामान्य C program निम्न sections से मिलकर बना होता है:

  1. Include Section

  2. Global Constants and Macro Section

  3. Function Declaration Section

  4. Main Function Section

  5. User-Defined Function Section


1. Include Section

The Include Section contains header files required by the program. Header files provide predefined functions and libraries to perform input-output operations, mathematical calculations, string handling, and other system tasks.

Include Section में वे header files शामिल की जाती हैं जिनकी आवश्यकता program को होती है। Header files predefined functions तथा libraries प्रदान करती हैं जिनकी सहायता से input-output operations, mathematical calculations, string handling तथा अन्य system tasks किए जाते हैं।

This section uses preprocessor directives such as:

इस section में preprocessor directives का उपयोग किया जाता है जैसे:

#include<stdio.h>
#include<conio.h>

Here:

  • stdio.h is used for standard input-output functions.

  • conio.h is used for console-related functions.

यहाँ:

  • stdio.h standard input-output functions के लिए उपयोग होती है।

  • conio.h console-related functions के लिए उपयोग होती है।


2. Global Constants and Macro Section

This section is used to define global constants, macros, and global variables which can be accessed throughout the program.

इस section का उपयोग global constants, macros तथा global variables को define करने के लिए किया जाता है जिन्हें पूरे program में access किया जा सकता है।

Example:

उदाहरण:

#define PI 3.14

The #define directive is processed before compilation by the preprocessor.

#define directive को compilation से पहले preprocessor द्वारा process किया जाता है।


3. Function Declaration Section

This section contains the declaration or prototype of user-defined functions that are used before the main() function.

इस section में उन user-defined functions की declaration या prototype दी जाती है जिन्हें main() function से पहले उपयोग किया जाना है।

Example:

उदाहरण:

float calculateSI(float,float,float);

Function prototypes help the compiler understand:

  • Function name

  • Return type

  • Number of parameters

  • Type of parameters

Function prototype compiler को निम्न जानकारी प्रदान करता है:

  • Function name

  • Return type

  • Number of parameters

  • Type of parameters


4. Main Function Section

The main() function is the most important part of every C program because program execution starts from the main() function.

main() function प्रत्येक C program का सबसे महत्वपूर्ण भाग होता है क्योंकि program का execution main() function से ही प्रारंभ होता है।

The main function generally contains:

  • Variable Declaration

  • Initialization

  • Executable Statements

  • Function Calls

  • Return Statement

main function में सामान्यतः निम्न भाग होते हैं:

  • Variable Declaration

  • Initialization

  • Executable Statements

  • Function Calls

  • Return Statement

Basic Syntax:

मूल Syntax:

int main()
{
// statements
return 0;
}

5. User-Defined Function Section

This section contains the definition of user-defined functions created by the programmer.

इस section में programmer द्वारा बनाए गए user-defined functions की definition दी जाती है।

Functions improve:

  • Code reusability

  • Program readability

  • Modular programming

Functions से:

  • Code reusability बढ़ती है

  • Program readability बेहतर होती है

  • Modular programming संभव होती है


Example Program: Simple Interest


C Program for Simple Interest साधारण ब्याज निकालने का सी प्रोग्राम 

File Name: si.c

#include<stdio.h>
#include<conio.h>
int main()
{
float p,r,t,si;
clrscr();
printf("Enter Principal, Rate and Time\n");
scanf("%f%f%f",&p,&r,&t);
si = p*r*t/100;
printf("Simple Interest = %f",si);
getch();
return 1;
}

Explanation of the Program प्रोग्राम की व्याख्या

#include<stdio.h>

This header file is used for input-output functions like printf() and scanf().

यह header file printf() और scanf() जैसे input-output functions के लिए उपयोग होती है।


#include<conio.h>

This header file is used for console functions like clrscr() and getch().

यह header file clrscr() और getch() जैसे console functions के लिए उपयोग होती है।


int main()

This is the starting point of program execution.

यह program execution का प्रारंभिक बिंदु है।


float p,r,t,si;

These variables are declared to store:

  • Principal

  • Rate

  • Time

  • Simple Interest

इन variables का उपयोग निम्न values को store करने के लिए किया जाता है:

  • Principal

  • Rate

  • Time

  • Simple Interest


scanf()

This function accepts input from the user.

यह function user से input प्राप्त करता है।


si = prt/100;

This statement calculates simple interest.

यह statement simple interest की गणना करता है।


printf()

This function displays output on the screen.

यह function स्क्रीन पर output प्रदर्शित करता है।


Output Example

आउटपुट उदाहरण

Enter Principal, Rate and Time
1000
5
2
Simple Interest = 100.000000

Importance of Understanding Program Structure प्रोग्राम स्ट्रक्चर को समझने का महत्व

Understanding the structure of a C program helps students:

  • Write organized programs

  • Debug errors easily

  • Improve programming logic

  • Build modular applications

  • Understand software development fundamentals

C program structure को समझने से विद्यार्थी:

  • Organized programs लिख पाते हैं

  • Errors आसानी से debug कर पाते हैं

  • Programming logic बेहतर बना पाते हैं

  • Modular applications विकसित कर पाते हैं

  • Software development fundamentals समझ पाते हैं

The structure of a C program provides a systematic way to write efficient and understandable code. Every section of a C program has a specific purpose, and together they create a complete executable application. Learning program structure is the first step toward becoming a professional programmer.

C program की संरचना efficient और understandable code लिखने का व्यवस्थित तरीका प्रदान करती है। C program का प्रत्येक section एक विशेष कार्य करता है और सभी sections मिलकर एक complete executable application बनाते हैं। Program structure सीखना professional programmer बनने की पहली सीढ़ी है।

Next Topic:- Basic and Important C Programs महत्वपूर्ण एवं सामान्य सी प्रोग्राम (Sequential Structure Programs)

No comments:

Post a Comment

C Program to Calculate Simple Interest with Output, Simple Interest Program in C Language

Simple Interest is one of the most common mathematical calculations used in banking, finance, education, and accounting systems. In C langua...