Your Ad Here

Tuesday, May 13, 2008

Q & A Session contd...

Question 3: What is printf() function?
Answer: printf() is a function defined in stdio.h library file and is used for printing output on the standard output device which is Monitor. This function takes 2 parameters:
1. The format string
2. The Variable

e.g.
printf("%d",num);

Here %d is the format string used, the format string tells the compiler which type of data needs to be shown on the standard output device. Some of the format specifiers are:

%d for integer values
%c for character values
%s for strings
%f for float values (these are the values with decimal point e.g 123.45)

Variable is the memory location in the primary memory where we store the value.

For more on printf() visit the links available.

Question 4: What is scanf() function?
Answer: scanf() is used for reading input from the standard input device which is keyboard. This function takes 2 parameters:
1. The format string
2. The address of the variable where the value will be stored.

e.g. scanf(“%d”, &num);

%d is used to tell the compiler that the value to be read is an interger value and the other parameter &num tells the compiler the memory location to put the value in. The “&” operator is used for accessing the address of a defined variable.

Some of the format specifiers are:

%d for integer values
%c for character values
%s for strings
%f for float values (these are the values with decimal point e.g 123.45)

For more on scanf() visit the links available.

No comments: