Published by: Nuru
Published date: 21 Jun 2021
printf("The value of x is %d", x);
The value of x is 15.
Format | Usual Variable type | Display |
---|---|---|
%c | char | single character |
%d (%i) | int | signed integer |
%e (%E) | float or double | exponential format |
%f | float or double | signed decimal |
%g (%G) | float or double | use %f or %e as required |
%o | int | unsigned octal value |
%p | pointer | address stored in pointer |
%s | array of char | sequence of characters(string) |
%u | int | unsigned decimal |
%x (%X) | int | unsigned hex value |
/*program */
#include
int main()
{
int x=10;
float f=3.56;
char ch=‘X’;
printf("Decimal NO x =%d",x);
printf("\n Octal No x = %o",x);
printf("\nHex NO x= %X",x);
printf("\nFloat No f= %G",f);
printf("\nFloat NO f =%f",f);
printf("\nFloat No f =%E",f);
printf("\nSingle Char ch = %c“,ch);
printf("\nString : %s","C-Program");
return 0;
}
Decimal NO x = 10
Octal No x = 12
Hex NO x = A
Float No f = 3.56
Float NO f = 3.560000
Float No f = 3.560000E+000
Single Char ch = X
String: C-Program
--------------------------------
The two most frequently used ways to display text strings is to use C's library functions printf() and puts().
The printf() function, part of the standard C library, is perhaps the most versatile way for a program to display data on-screen.
printf("An error has occurred!");
Displays: An error has occurred!
puts(“An error has occurred!”);