***Welcome to ashrafedu.blogspot.com * * * This website is maintained by ASHRAF***

Posts

Sunday, November 8, 2020

Parts of Simple C program

The best way to learn C or any programming language is to begin writing programs in it.

Let us write the first program named first.c :

/* A Simple C Program */

#include <stdio.h>

int main(void)

{

printf(“C is Sea\n”);

return 0;

}

C uses a semicolon as a statement terminator; the semicolon is required as a signal to the compiler to indicate that a statement is complete.

There are a few important points to note about thisprogram. These are common to all C programs.

 

1.      In C, the comments can be included in the program. The comment lines start with /* and terminate with */. These statements can be put anywhere in the program. The compiler considers these as non-executable statements.

        According to C99, a comment also begins with // and extends up to the next line break. So the                comment line can be written as follows:

        // A Simple C Program

 2.      In C, all lines that begin with # are directives for the preprocessor, which means that all these directives will be processed before the program is actually compiled. The #include directive includes the contents of a file during compilation.

 3.      Every C program contains a function called main. This is the starting point of the program. A C program may contain one or more functions one of which must be main(). Functions are the building blocks of a C program.

A C program basically consists of the following parts −

·             Preprocessor Commands

·             Functions

·             Variables

·             Statements & Expressions

·             Comments

 



No comments:

Post a Comment

Top