C Programming - Const - Discussion
Discussion Forum : Const - Point Out Errors (Q.No. 5)
5.
Point out the error in the program.
#include<stdio.h>
int main()
{
const int x;
x=128;
printf("%d\n", x);
return 0;
}
Answer: Option
Explanation:
A const variable has to be initialized when it is declared. later assigning the value to the const variable will result in an error "Cannot modify the const object".
Hence Option B is correct
Discussion:
2 comments Page 1 of 1.
Swati said:
6 years ago
As constant is initialized to 0 as soon as it is declared therefore if we want to initialize constant then it should be done at the time of declaration only.
Lingam said:
8 years ago
I can't understand please tell me how?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers