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
πŸ’¬ Discuss
βœ… Correct Answer: (B) 4 8 8
Explanation:

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.

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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
294
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Akash Lawaniya
Publisher
πŸ“ˆ
90%
Success Rate