C Programming

Program Description

Posted on 02nd May 2013

In this chapter we analyse each line of our first program, FirstProgram.c

Line 1: #include tells the C preprocessor to include the contents of the specified file in the source program. So in this case we instruct the preprocessor to include the system header file stdio.h which provides the standard input and output functions in C.
You will learn more about the pre-processor and the various preprocessior directives in later chapters of this tutorial.

Line 2: Every C program must contain this line somewhere in the program. This line declares the main function. A program starts execution from the start of main function. The int before main denotes that this function returns a integer value.

Line 3: The opening curly bracket or opening brace defines the start of a block of code for the main function.

Line 4: This line calls the printf() function which prints output to the standard output stream, in this case it prints the message "Hello, I am an aspiring C Programmer" to the command prompt window.

Line 5: The getchar() function reads a character input from the standard input stream which is a keyboard.

Line 6: The execution of the program terminates at the return statement and returns the integer value 0 back to the Operating System. A zero return value normally means the program completed successfully.

Line 7: And finally the closing curly bracket or closing brace defines the end of the main function.

Comments

Comments are lines of text that are ignored by the compiler. They make the program more readable to humans. Any text that starts with /* will be ignored until the next */ is encountered. Most C compilers also accept the C++ style // comments. Any text after the // will be ignored until the end of the line. It is a good programming practise to add comments to explain your program.

You can add a comment anywhere in your program:

#include <stdio.h>
int main() {

/* This is the start of the comment ..
This is a program to blah..blah ..
blah..blah .. blah..blah ..
End of the comment */

 	printf("Hello, I am an aspiring C Programmer");
 	return (0);
}

In the above example the text between /* and */ are ignored by the compiler.

Post a comment

Comments

Nothing yet..be the first to share wisdom.