Discussion
In a C program, following variables are defined:
float x = 2.17;
double y = 2.17;
long double z = 2.17;
Which of the following is correct way for printing these variables via printf.
Answer: A
Correct answer: printf("%f %lf %Lf",x,y,z);
A float passed to a variadic function is promoted to double, so %f serves for both float and double, and %lf is accepted as a synonym for the same. A long double is not promoted and needs its own specifier, %Lf with a capital L; using %f for it reads the wrong number of bytes.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development