printf is used to O/P data to STDOUT (usually the screen). It has many formatting options which we shall look at in a moment.
#include <stdio.h>
main()
{
printf("This text will appear on the screen\n");
}
|
printf is passed one formatting argument. The unusual thing about the example (in my mind) is \n, this is actually an escape sequence that signals a new line. Without it, any printf's that follow would O/P to the same line. printf also takes extra arguments which are inserted into the format string at locations marked with a %.
#include <stdio.h>
main()
{
int number=42;
printf("The answer is %i\n", number);
}
|
What happens here is the %i is seen as a formatting identifer for the next argument (number). In this case an integer is expected.
| Top | Master Index | Keywords | Functions |