Which is the correct way to declare and initialize a float?
Q.Which is the correct way to declare and initialize a float?
A) decimal pi = 3.14;
B) float pi = 3.14f;
C) float: pi = 3.14;
D) pi float = 3.14;
Correct Answer:
Option B
Detailed Explanation:
B) float pi = 3.14f; is correct. C++ declarations use the data type before the variable name. Integer division drops the fractional part, character codes can be converted to integers, and constants cannot be changed.