Structure of a C program



Every C program has one or more functions in it. A program always begins by executing the main() function. Each function contains:

• A function heading: This consists of a function name followed by an optional list of arguments enclosed in parentheses.

• A list of argument declarations, if arguments are included in the heading. Arguments are also called parameters.

• A compound statement: This comprises the remainder of the function.

• Each compound statement is covered within a pair of braces { }. The braces may contain elementary statements called expression statements. Each expression statement must end with a semicolon (;).


➡️Brief structure


     Constant declarations


     main() function /* comments*/


     variable declarations


     executable statements


➡️Format of a C Program


     [constant declarations];


     [external variable declarations]; returntype

     main()


     {


               [variable declaration]; 

               [program statements]; 

     return value;


     }


               [additional functions]



1.main( ) function: C program is a set of functions, but the main function is essential. The program execution starts at the main function. The body of a function is enclosed in a set of braces. The returntype indicates the datatype of the return value of the main( ) function. 

2. Variable declarations: All the variable names and their types are to be defined beforehand.

3. Executable statements: These statements follow the variable declarations and terminated by semicolon. A statement may be expressed either in one line or across lines. This is because, C ignores new lines, spaces, tabs, etc.

          Generally a programming language is designed so as to support certain kind of data, such as numbers, characters, strings etc. A program is nothing but a set of statements and expressions to accomplish a specific task, which are being executed in a sequential manner. These statements/instructions are formed using certain words and symbols according to the rules known as syntax or grammar of the language. The words and symbols are framed by using different characters permitted by the language compiler. Following is the set of characters permitted by different C compilers.

Comments

Popular posts from this blog

Automations and robotics

Solid Pattern Program In Java Language

Palindrome Pattern Program In Java Language