Bird
0
0

Which of the following is the correct way to declare a variable of type float in C?

easy📝 Syntax Q12 of 15
C - Variables and Data Types
Which of the following is the correct way to declare a variable of type float in C?
Aint number = 3.14;
Bchar number = 3.14;
Cfloat number = 3.14;
Dbool number = 3.14;
Step-by-Step Solution
Solution:
  1. Step 1: Check variable declaration syntax

    In C, to declare a float variable, use the keyword float followed by the variable name and value.
  2. Step 2: Match type with value

    Assigning 3.14 (a decimal) to a float variable is correct. Other types like int, char, or bool cannot hold decimal values properly.
  3. Final Answer:

    float number = 3.14; -> Option C
  4. Quick Check:

    Decimal numbers use float type [OK]
Quick Trick: Use float keyword for decimal numbers [OK]
Common Mistakes:
  • Using int for decimal values
  • Assigning decimal to char
  • Using bool for numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes