In the following C declarations and statements: int ram; float alpha, gamma; ram = 6400; alpha = 0.562; gamma = alpha * ram + 1; which statements are correct: (1) ram is an integer variable, (2) alpha and gamma are real (float) variables, (3) * and + are arithmetic operators, (4) 0.562 may be an integer or real constant?

Difficulty: Easy

Correct Answer: 1, 2, 3 only

Explanation:


Introduction / Context:
This question checks foundational C knowledge: basic data types (int, float), operators (*, +), and numeric literal classification (integer vs real/floating constants).


Given Data / Assumptions:

  • Declarations: int ram; float alpha, gamma;
  • Assignments: ram = 6400; alpha = 0.562; gamma = alpha * ram + 1;
  • Statements to evaluate: (1) ram is an integer variable, (2) alpha and gamma are real variables, (3) * and + are arithmetic operators, (4) 0.562 may be an integer constant or real constant.


Concept / Approach:
Map each statement against C rules: types from declarations, operator categories, and literal kinds. A number with a decimal point is a floating (real) constant, not an integer constant.


Step-by-Step Solution:

Check (1): 'int ram;' → ram has type int → statement (1) is true.Check (2): 'float alpha, gamma;' → both are float (real) → statement (2) is true.Check (3): In C, * and + are arithmetic operators (multiplication and addition) → statement (3) is true.Check (4): The literal 0.562 includes a decimal point → it is a floating (real) constant, not an integer constant → statement (4) is false.


Verification / Alternative check:
Compiler perspective: '0.562' tokenizes as a floating literal; integer constants have no decimal point and optional suffixes. Therefore, (4) cannot be true in C.


Why Other Options Are Wrong:

  • All: Incorrect because (4) is false.
  • 2, 3, 4 only: Incorrect because (4) is false and (1) is true.
  • 1, 2, 4 only: Incorrect because (4) is false; (3) is true.


Common Pitfalls:

  • Assuming any numeral can be either int or float; the decimal point determines a floating literal.
  • Overlooking that 'float' variables are commonly called 'real' in older terminology.


Final Answer:
1, 2, 3 only

Discussion & Comments

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