Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program in 16-bit platform (Turbo C under DOS) ?

#include <stdio.h>

int main()
{
    printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));
    return 0;
}

 

  • A.8, 1, 4
  • B.4, 2, 8
  • C.4, 2, 4
  • D.10, 3, 4

Answer: B

Correct answer: 4, 2, 8

On a 16-bit Turbo C target: 3.0f is a float, 4 bytes; '3' is a character constant, which has type int in C, so 2 bytes on that platform - not 1; and 3.0 with no suffix is a double, 8 bytes. The character constant is the trap: it is an int in C and a char only in C++.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.