More Questions from Microprocessors

In the C programming language, which of the following is not a valid representation of a real (floating-point) constant?

Electronics and Communication Engineering Microprocessors Difficulty: Easy
Choose an option
  • A
    426
  • B
    321.0
  • C
    -621.231
  • D
    +201.2314

Answer

Correct Answer: 426

Explanation

Introduction:This question distinguishes integer constants from floating-point (real) constants in C. Understanding literal forms helps prevent unintended type choices and implicit conversions.

Given Data / Assumptions:

  • Options include an integer-looking token (426) and classic decimal forms with optional signs.
  • Context: C numeric literal grammar for floating constants.

Concept / Approach:

In C, a floating (real) constant typically has a decimal point and/or an exponent part (e.g., 1.0, .5, 2e3, -3.14, +6.02e23). An integer constant lacks a decimal point and exponent (e.g., 426) and therefore is not a real constant. A leading plus or minus is a unary operator applied to the literal token; it does not invalidate the floating form.

Step-by-Step Solution:

Step 1: Inspect '321.0' — decimal point present, valid floating literal.Step 2: Inspect '-621.231' — unary minus with decimal, valid floating literal.Step 3: Inspect '+201.2314' — unary plus with decimal, valid floating literal.Step 4: Inspect '426' — no decimal point or exponent, thus an integer literal, not a real constant.

Verification / Alternative check:

Compilers will type '426' as an int by default, whereas literals with a decimal point are typed as double unless suffixed (e.g., f/F for float).

Why Other Options Are Wrong:

All other options contain a decimal point and thus are valid real constants in C.

Common Pitfalls:

Confusing the presence of a sign with type; forgetting exponent notation also creates real constants (e.g., 1e2).

Final Answer:

426

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