First we’ll see the simplest C program then we’ll write a general structure of C program.
Hello world Program in C :
#include<stdio.h> /*header file */
void main()
{
printf(”Hello world”); /*output statement*/
}
The first line in the above programme is :
1) #include<stdio.h>
Means :
In ‘C’ programming language all library functions are included in different header files in different categories with “.h” extension.
# is called as “preprocessor”. Means it will include the header file before compiling the code. “include” gives command to include something
“stdio” stands for “standard input output”. As it is a header file so .h extension is there. It contains some standard functions related to input and ouput such as “printf”, “scanf”.
Second Line :
2) main() and void main()
Means :
main() declares the start of the function.
Void means that this is not going to return any value. So, void main means that this main function will not return any value. Main is also written as int main, meaning that this function is going to return an integer value. If you want your function to return a value, prefix the name of the function with the type returned. For ex- to return a float value, you write float main() or float marksheet(). Same way, for integers, we write int main().
Third Line :
3) {
Opening Braces to write the statement in void main() Block.
Forth Line :
4) printf(”Hello world”);
printf prints the words on the screen. The text to be printed is enclosed in double quotes.
printf formats the given arguments according to the format string, and writes them to the standard output.
The Semicolon in the last of a statement means the termination of that statement.
Fifth Line :
5) }
The Closing Braces means the end of the statements in the void main() block.
The two curly braces { } shows the start and finish of the function.
/* */ are used for comments and they may appear anywhere in the program.Such comments are helpful in identitifying the program’s principal features.
Now we can write the structure of the C program
Preprocessor directives /*header files*/
Global data declerations
main()
{
Decleration part;
Program statements;
}



Recent Comments