Constants
- What will be the output of the following program:-
#include
int main() { const int a=34; int b=128; a = b; printf("%d\n",a); return 0; }
-
View Hint View Answer Discuss in Forum
const is a type specifier, when used with a data type, its value cannot be modified
Correct Option: C
Compiler marks a as read only, any attemp to modify the value will generate compiler error.
- What will be the output of the following C code?
#include <stdio.h>
int const Result()
{
printf("interviewmania.com");
return 0;
}
void main()
{
Result();
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
interviewmania.com
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int const m = 10;
m++;
printf("m is %d", m);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Constant variable has to be declared and defined at the same time. Trying to change it results in an error.
- Which of the following statement is false?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Since the constant variable has to be declared and defined at the same time, not doing it results in an error.
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int n = 21;
int *const m = &n;
int s = 12;
m = &s;
printf("%d", m);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Since the pointer m is declared to be constant, trying to assign it with a new value results in an error.