Basic of C language and function of C explain in detail.

SAMPLE PROGRAM FOR PRINTING A MESSAGE:

Consider a very simple program 

#include<stdio.h>
int main(){
    /*  printing begins*/
    printf("Mr programmer Boss");
      /*  printing ends*/
    return 0;
}

This program when executed will produce the following output

 Mr programmer Boss 

Let as have a close look at the program. The first line informs the system that the name of the program is main and the execution begins at this line. The main() is a special function used by C system to tell the computer 8where the program start. Every program must have exactly one main function. If we use more then one main function, the compiler can not understand which one marks the beginning of the program.

The empty pair of parentheses immediately following main indicates that the function main has no argument (parameter).

The opening brace “{“ in the second line marks the beginning of the function main and the closing brace “}” in the last line indicates the end of the function. In this case, the closing brace also marks the end of the program. All the statement between this two braces from the function body. The function body contains a set of instructions to perform the given task.

In this case, the function body contains three statement out of which only the printf line is an executable statement. The lines beginning with /* and ending with */ are known as comment line. This are used in program to enhance its readability and understanding. Comment lines are not executable statement and there for anything between /*and*/ is ignored by the compiler. In general, a comment can be inserted when ever blank spaces can occur---at the beginning, middle or end of a line----“but never in the middle of the word”.

Although comments can appear any where they cannot be nested in C. that means, we can not have comments inside comments. once the compiler finds an opening token, it ignores everything until it finds a closing token. The comment line /*=============/*=============*/============*/ is not valid and therefore result in an error.

Since comments do not affect the execution speed and the size of a compiled program, we should use them liberally in our program. They help the programmers and other users in understanding the various functions and operations of a program and serve as an aid to debugging and testing. We shall see the use of comment lines more in the example that follow.

Lets as now look at the printf() function, the only executable statement of the program

Printf(“Mr programmer boss”);

Printf is a predefined standard C function for the printing output. Predefined means that it is a function that has already been written and compiled, and linked together with our program at the time of linking. The printf function causes everything between the starting and the ending quotation marks to be printed out. In this case, the output will be:

Mr programmer boss

Note that the print line ends with a semicolon. Every statement in C should end with semicolon (;) .

#include<stdio.h> :

At the beginning of all programs that use any input/output library functions. However, this is not necessary for the functions printf and scanf which have been defined as a part of the C language.

Before we proceed to discuss further example, we must note one important point. C dose not make a distinction between uppercase and lowercase letters. For example, printf and PRINTF  are not the same. In C, everything is written in lowercase letters. However, uppercase latter are used for symbolic name representing constants. We may also used upper case latter in output strings like “ MR PROGRAMMER” and “BOSS”.

Above example that printed Mr programmer boss is one of the simplest program. Figure highlights the general format of such simple programs. All C program need a main function.

THE MAIN FUCTION OF C:

The main is a part of every C program .C permits different forms of main statement. following form

  • main()
  • int main()
  • void main()
  • main(void)
  • void main(void)
  • int main(void)

the empty pair of parentheses indicates that the function has no arguments. This may be explicitly indicate by using the keyword void inside the parentheses.

practical of c language

 




0 Comments