Sunday 1 November 2015

SAMPLE C PROGRAM 1


First, we will see a simple C program and learn the basic structure.
OUTPUT 
LINE 1  : /* The following program print a line of text.*/ 
'/*' is used to mark the start of a comment and it terminate with '*/'
A comment used in the program is ignored by the compiler
Comments are used to enhance program readability and understandability by giving the description or other detail about the program
There must be no gap between the asterisk (*) and slash (/)
Comments may be placed anywhere in the program, but are not allowed in the middle of any keyword or identifier

LINE 2 : #include<stdio.h>
It is a pre-processor directive.
Lines begin with # are processed by pre-processor before the program is compiled
The above line tells the pre-processor to include the contents of the Standard Input/Output header file (stdio.h) in the program
This header file contains information and declarations used by the compiler when compiling standard input /output library functions such as printf, scanf, etc.

LINE 3 : main() 
This is a compulsory part of every C program
C program contains one or more functions and one must be main() 
Execution of every C program begins from the function main() 
Hence, every C program must have (only) one main() function.

LINE 4 : { 
Left brace denotes beginning of the body of the function or code-block, here the beginning of function main() 
LINE 6 : }  
Right brace denotes end of the body of the function or code-block, here the end of function main() 
Body of every function must begin with { and end with the corresponding }
The portion of the program between these two braces is called a block
The block is an important unit in C
LINE 5 : printf("Welcome to C Language with Classmate\n");
The above statement instructs the computer to perform some action – to print the string of characters, marked by the double quotes, on the screen.
So it prints the message "Welcome to C Language with Classmate” on the screen
\n’ is not printed on the screen
Backslash (\) is called the escape character
It indicates that printf is supposed to do something out of ordinary properties
printf combines the \ and the next character to form an escape sequence
\n is such an escape sequence, means newline and it causes the cursor to move to the beginning of the next line

No comments:

Post a Comment