Input and Output Functions

 

C Program Form

Form of C program refers to the statement of how it is written or typed. There are certain rules about the form of a C program that is applicable to all C program.

1. Each statement in a C program is written as a separate statement.
2. Statements in a program must appear in the same order in which we wish them to be executed.
3. Blank spaces may be inserted between two words to improve readability.
4. Every C statement must end with a ; i.e terminator.

Comments in C program:

Comments are used in C program to clarify either the purpose of the program or the purpose of some states in the program.

1. Comments about the program should be enclosed within /* */.
2. Thus comments are not necessary,it is a good practice to begin a program with a comment indicating the purpose of the program.
3. Any number of comments can be written at any place in the program. 

main():

main() forms the crucial part of any C program. main() is a function . A function is nothing but a set of statements. In a c program there can be multiple functions.All statement that are belong to main() are enclosed in between { } . Function in C returns value main() function always returns an integer value, hence there is int before main().

First C Program:

#include<stdio.h>
int main()
{
    printf("Hello world");
}

printf():

C does not contain any instructions to display output on the screen.All output to screen is achieved using readymade library functions. One such function is printf(). 

General form of printf()  is printf(<"string">,<list of variables>).

<string> can contain 
%f for printing real values.
%d for integer values.
%c for printing character values.

scanf(): 

To make the program general, the program should ask the user to supply the values of sum, add and other variables through the keyboard during the execution.This can be achieved using a function called scanf(). printf() outputs the values to the screen whereas scanf() receives them from the keyboard.

scanf("%d",&sum);        /* %d is used for integer value and sum is variable */

The ampersand (&) before the sum in scanf() function is must. & is address of operator. It gives the location number used by the variable in the memory.



Post a Comment

0 Comments