If you have any query feel free to chat us!
Happy Coding! Happy Learning!
In C, the printf() function is a standard library function that is used to output text to the console. It takes a format string and a set of arguments, and prints the formatted output to the console. The format string is a string that contains special placeholders called format specifiers, which indicate how the corresponding arguments should be formatted.
Here is an example of how to use the printf() function:
Copy code
#include <stdio.h>
int main() {
int x = 5;
float y = 3.14;
char z = 'A';
printf("x = %d, y = %f, z = %c\n", x, y, z);
return 0;
}
In this example, the format string is "x = %d, y = %f, z = %c\n", which contains three format specifiers: %d, %f, and %c. The format specifiers indicate that the first argument should be formatted as an integer, the second argument should be formatted as a floating-point number, and the third argument should be formatted as a character.
The printf() function supports several format specifiers, including:
It's also possible to include width and precision in the format specifiers for example, %5d for a width of 5
Comments: 0