Correct way to define a value 6.28 in a variable ‘pi’ where value cannot be modified?

Mỹ An

New member
Correct way to define a value 6.28 in a variable ‘pi’ where value cannot be modified?
A. #define pi 6.28F
B. pi = 6.28F
C. const float pi = 6.28F
D.
const float pi
pi = 6.28F
 
Answer: c
Explanation: Const is a reserve keyword whenever they are declared with any variables. The value stored in that variable always remain fixed. Any modification done to change value of that variable results in error. Hence, options #define pi 6.28F, pi = 6.28F and const float pi, pi = 6.28F are rejected because the value is not declared fixed. Now, for value only option ‘const float pi = 6.28F’ is correct because for value while declaring a constant variable we need to provide a constant value too as provided in const float pi = 6.28F. So, option const float pi = 6.28F is correct way of declaration of constant variable.
 

Tìm kiếm

Back
Top