MCS-011 Problem Solving and Programming

First year, Semester 1

Chapters

Newsletter

Structure of a C program

As we have already seen, to solve a problem there are three main things to be considered. Firstly, what should be the output? Secondly, what should be the inputs that will be required to produce this output and thirdly, the steps of instructions which use these inputs to produce the required output. As stated earlier, every programming language follows a set of rules; therefore, a program written in C also follows predefined rules known as syntax. C is a case sensitive language. All C programs consist of one or more functions. One function that must be present in every C program is main(). This is the first function called up when the program execution begins. Basically, main() outlines what a program does. Although main is not given in the keyword list,it cannot be used for naming a variable. The structure of a C program is illustrated below where functions func1( ) through funcn( ) represent user defined functions. 


Preprocessor directives
Global data declarations
main ( ) /* main function*/
 {
 Declaration part;
 Program statements;
 }
 /*User defined functions*/
 func1( ) { ………… }
 func2 ( ) { ………… }
 .
 .
 .
 funcn ( ) { ………… }


A Simple C Program 

From the above sections, you have become familiar with, a programming language and structure of a C program. It’s now time to write a simple C program. This program will illustrate how to print out the message “This is a C program”.

Report an issue

Reporting: Structure of a C program (topic)

Related Posts