Pages

Of Computers, troubles and my Experiments with programming as a beginner.

Thursday, March 20, 2008

Printf() Function

printf() is a very commonly used funtion in C language. This is replaced in C++ by the cout, which is easier to write for a programmer. But printf() gives you control over the data type of the variable that you use. It writes to the standard output stream. It is contained in the C standard library. It can sometimes be used without having to include any header files. However, in some old compilers, it is found that stdio.h is to be included to be able to use printf.
printf stands for print formatted. The data type control can be achieved by means of format specifiers which are as follows,
%d for integers
%f for float
%u for unsigned integer
%e for double
%c for character
printf() has a syntax as follows:
printf("string" %d,variable);
the %d here in this syntax is an example. It can be replaced by other format specifiers.

No comments: