Which format specifier is used to print an integer value?
A
%i B
%d C
%int D
Both A and B
Analysis & Theory
Both %d and %i are used to print integer values in printf().
Which format specifier prints a *floating-point number*?
A
%d B
%c C
%f D
%s
Analysis & Theory
%f is used to display float or double values.
What is %s used for?
A
Single character B
String C
Integer D
Special symbol
Analysis & Theory
%s is used for printing strings (character arrays).
Which format specifier is used to display a *character*?
A
%char B
%ch C
%c D
%s
Analysis & Theory
%c prints a single character.
How can you print a value with 2 decimal places?
A
printf("%f", x); B
printf("%.2f", x); C
printf("%2f", x); D
printf("%0.2", x);
Analysis & Theory
%.2f rounds and displays two digits after the decimal point.
Which format specifier is used to print hexadecimal values?
A
%h B
%x C
%X D
Both B and C
Analysis & Theory
%x prints hexadecimal in lowercase, %X in uppercase.
What will be the output?
c
int a = 97;
printf("%c", a);
A
97 B
a C
A D
Error
Analysis & Theory
%c converts ASCII value 97 to character 'a'.
Which format specifier is used to *read an integer* using scanf()?
A
%f B
%s C
%d D
%i
Analysis & Theory
%d is commonly used in scanf() to read integer values.
Which of the following is used to print a *memory address*?
A
%m B
%p C
%a D
%&
Analysis & Theory
%p prints a pointer (i.e., a memory address).
What is the result of the following code?
c
float f = 3.1459;
printf("%.1f", f);
A
3.1459 B
3.1 C
3.14 D
3.2
Analysis & Theory
%.1f rounds 3.1459 to 1 decimal place: 3.1, but rounding gives 3.2.