C# Programming - Datatypes - Discussion
Discussion Forum : Datatypes - General Questions (Q.No. 12)
12.
Which of the following is the correct ways to set a value 3.14 in a variable pi such that it cannot be modified?
Discussion:
5 comments Page 1 of 1.
Dheeraj said:
1 decade ago
C and D both are answer. Because const float pi = 3.14F; it is correct. And const float pi; pi = 3.14F;
suppose I don't take value of pi it is garbage collected and I feed value of pi that is occurred.
suppose I don't take value of pi it is garbage collected and I feed value of pi that is occurred.
(1)
Gopesh said:
1 decade ago
Since the question is we have to set a value 3.14 in a variable pi such that it cannot be modified, so we have to use 'const' keyword. But we can't write (const float pi; pi = 3.14F;) because here we are modifying the value of pi.
VISHWANATH said:
1 decade ago
The same is observed with #define pi 3. 14.
Can any one please tell why can't we use this ?
Can any one please tell why can't we use this ?
Abhijit said:
1 decade ago
Const keyword is used for declaring a Constant variable,where Constant variable must be declare at the time of declaration only.
Syntax for declaring Constant is :
[const]<type><var><=value>
Syntax for declaring Constant is :
[const]<type><var><=value>
Sanjay bisht said:
1 decade ago
# define pi 3.14 defines "pi" as replaceable with 3.14 meaning 3.14 can be replaced with the word "pi". The question wants to allocate "pi"(variable) the value 3.14. hence #define is substitution.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers