Basic Structure of a C Program

A C program generally has the following parts:
§  Preprocessor Commands
§  Functions
§  Variables
§  Statements & Expressions
§  Comments

Let us consider a C Program:
#include<stdio.h>
void main()
{
printf("Hello, World!");
}

Preprocessor Commands: These commands tells the compiler to do some preprocessing before executing the actual compilation. For example, “#include <stdio.h>” is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation.

Functions:  These are main building blocks of any C Program. Every C Program will at least have one function which is a mandatory function called main() function. This function is prefixed with keyword int or void or any other datatype. This defines the return type of the function. For int main() the program will return an integer value to the terminal (system).
The C Programming language provides a set of built-in functions. In the above example printf() is a C built-in function which is used to print anything on the screen.

Variables: These are used to hold numbers, strings and complex data for manipulation.

Statements & Expressions: Expressions combine variables and constants to create new values. Statements are expressions, assignments, function calls, or control flow statements which make up C programs.

Comments: are used to give additional useful information inside a C Program. All the comments will be put inside /*...*/

Note
•C is a case sensitive programming language. It means in C printf and Printf will have different meanings.
•C has a free-form line structure. End of each C statement must be marked with a semicolon.
•Multiple statements can be on the same line.
•White Spaces (ie tab space and space bar ) are ignored.
•Statements can continue over multiple lines.

Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C