On a 16-bit Turbo C/DOS platform (int=2 bytes), what does sizeof report for these literals? #include<stdio.h> int main() { printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0)); return 0; }

Difficulty: Easy

Correct Answer: 4, 2, 8

Explanation:


Introduction / Context:
This question targets legacy 16-bit Turbo C/DOS conventions. While modern platforms often have int=4 bytes, Turbo C typically uses int=2 bytes, float=4 bytes, and double=8 bytes. Character constants have type int, so they take 2 bytes in this environment.



Given Data / Assumptions:

  • float size = 4 bytes (sizeof(3.0f)).
  • int size = 2 bytes on 16-bit Turbo C → sizeof('3') = 2.
  • double size = 8 bytes (sizeof(3.0)).


Concept / Approach:
sizeof yields the storage size of the operand’s type. A floating literal with suffix f is float. A character constant has type int (not char). A floating literal without suffix is double. These rules are consistent across standard C, but the exact byte counts reflect the target data model.



Step-by-Step Solution:
Compute sizeof(3.0f) → 4.Compute sizeof('3') → sizeof(int) → 2 (on Turbo C 16-bit).Compute sizeof(3.0) → sizeof(double) → 8.Printed result: 4, 2, 8.


Verification / Alternative check:
Print sizeof(int), sizeof(float), sizeof(double) on the same compiler to confirm assumptions; results align with the final line.



Why Other Options Are Wrong:
(a), (c), (d), and (e) contradict the 16-bit Turbo C data model and C literal typing rules.



Common Pitfalls:
Assuming modern 32/64-bit sizes; thinking a char constant has type char.



Final Answer:
4, 2, 8

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion