Monday, April 06, 2009

Utility of scanf() function and how it is used.

Utility of scanf() is to input data from the user. The format string used in the printf() statement is same for scanf() statment, only difference is that we have to space & sign before the variable name, and we can’t print any word or statement to make the input user friendly with the scanf() function, to make the input statement user friendly, we have to pint the statement using printf() function and then we have to use scanf() function to input the data.
Syntax of scanf() function is as follows:
scanf(“<format string>”, &<variable name>);



Some of the examples of scanf() function, are as follows:
scanf(“%d”, &t);      /* used to input integer value, where t is an integer type variable */
scanf(“%f”, &p);      /* used to input float value, where p is a real or float type variable */
scanf(“%c”, &ch);      /* used to input character value, where ch is a character type variable */
scanf(“%d %f %c”, &t, &p, &ch);         /* used to input different types of value at once */

No comments:

Post a Comment

Please give your valuable comments or queries if you fell its helpful or if you like the contents of the site. Thanks...