C3. The General form of simple C Program


The General Form of a Simple Program
Let's take a closer look at below programme and see how we can generalize it a bit. Simple C programs have the form
directives
int main(void) {
statements
}
Notice how the braces show where main begins and ends. C uses { and } in much the same way that some other languages use words like begin and end. This illustrates a general point about C: it relies heavily on abbreviations and spe­cial symbols, one reason that C programs are concise .

Even the simplest C programs rely on three key language features: directives (editing commands that modify the program prior to compilation), functions (named blocks of executable code, of which main is an example), and statements (commands to be performed when the program is run). We'll take a closer look at these features now.

#include
void main()
{
int a = 10, b = 20, c;
printf(“\n original values of  a = %d, b = %d, a, b);
 c = a;
 a = b;
 b = c;
printf(“\n Swapped Values of a = %d, b = %d”, a, b);

 }
#include
It is necessary to “include” information about C's standard I/O (input/output) library. The program's executable code goes inside main, which represents the “main” program. The only line inside main is a command to display the desired message, printf is a function from the standard I/O library that can produce nicely for­matted output. The \n code tells printf to advance to the next line after printing the message. The line
return 0;
indicates that the program “returns” the value 0 to the operating system when it ter­minates.

No comments: