A

Akash Lawaniya • 9.58K Points
Tutor III

Q. Which of the following is the correct output for the program given below?

Code:
#include <stdio.h>
int main ( )
{
     printf ("%d %d %d\n" , sizeof(2.19f), sizeof(2.19), sizeof (2.19l));
     return 0 ;
}
  • (A) 4 4 4
  • (B) 4 8 8
  • (C) 4 8 10
  • (D) 4 8 12

Explanation by: Mr. Dubey

The sizeof() operator returns the size (in bytes) of a data type or expression. Let's analyze each argument inside printf:

Breakdown of sizeof() calls:

  1. sizeof(2.19f) → 2.19f is a float, which typically takes 4 bytes.
  2. sizeof(2.19) → 2.19 is a double (default type for floating-point literals in C), which typically takes 8 bytes.
  3. sizeof(2.19l) → 2.19l (or 2.19L) is a long double, which usually takes 10 bytes on most systems (but may be 12 or 16 bytes on some architectures).

Thus, the output is 4 8 10.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics