Bird
0
0

Which of the following is a correct way to declare and initialize a float variable named price with value 9.99?

easy📝 Conceptual Q2 of 15
C - Variables and Data Types
Which of the following is a correct way to declare and initialize a float variable named price with value 9.99?
Afloat price = '9.99';
Bfloat price = 9.99;
Cfloat price = "9.99";
Dfloat price = 9,99;
Step-by-Step Solution
Solution:
  1. Step 1: Check correct float initialization syntax

    Float variables are assigned numeric values with a decimal point using dot notation, without quotes.
  2. Step 2: Identify invalid options

    float price = '9.99'; uses single quotes (character), C uses double quotes (string), D uses comma instead of dot.
  3. Final Answer:

    float price = 9.99; -> Option B
  4. Quick Check:

    Float initialization uses numeric literal with dot = B [OK]
Quick Trick: Use dot for decimals and no quotes for float values [OK]
Common Mistakes:
  • Using quotes around numeric values
  • Using comma instead of dot for decimals

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes