Variables & Constant Multiple Choice Questions 1 : Const Variable
Predict the Output of the Following Program if Given Things are -
#include<stdio.h>
void main()
{
const int num ;
num = 10;
printf("%d",num);
getch();
}Options :
- 10
- Nothing Will be Printed
- Compile Error
- Run Time Error
Output:
How and Why ?
- You get Two Errors Here
- Const Indicates that the Variable is of Constant Type and Cannot be modified
- num = 10 attempts to modify num in Program Which is Illegal
Rules :
- Const Variable Should be Initialized as soon as it is declared
- Const Cannot be Modified
Errors :
- Constant variable ‘num’ must be initialized
- Cannot modify a const object


