C Programming - Const - Discussion
Discussion Forum : Const - Find Output of Program (Q.No. 7)
7.
What will be the output of the program?
#include<stdio.h>
int get();
int main()
{
const int x = get();
printf("%d", x);
return 0;
}
int get()
{
return 20;
}
Answer: Option
Explanation:
Step 1: int get(); This is the function prototype for the funtion get(), it tells the compiler returns an integer value and accept no parameters.
Step 2: const int x = get(); The constant variable x is declared as an integer data type and initialized with the value "20".
The function get() returns the value "20".
Step 3: printf("%d", x); It prints the value of the variable x.
Hence the output of the program is "20".
Discussion:
3 comments Page 1 of 1.
Arnav said:
1 decade ago
Will there be any problem as the function returns int value but x is a const int? please explain.
Tripti said:
10 years ago
We always use () after return function. In this program we can see it is only return 20 which is wrong.
Saifuddin said:
9 years ago
What will be the answer, please?
Hourglass, row = 7.
DCBABCD
CBABC
BAB
A
BAB
CBABC
DCBABCD
Hourglass, row = 7.
DCBABCD
CBABC
BAB
A
BAB
CBABC
DCBABCD
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers