C Programming - Const - Discussion
Discussion Forum : Const - Find Output of Program (Q.No. 10)
10.
What will be the output of the program?
#include<stdio.h>
int main()
{
const c = -11;
const int d = 34;
printf("%d, %d\n", c, d);
return 0;
}
Answer: Option
Explanation:
Step 1: const c = -11; The constant variable 'c' is declared and initialized to value "-11".
Step 2: const int d = 34; The constant variable 'd' is declared as an integer and initialized to value '34'.
Step 3: printf("%d, %d\n", c, d); The value of the variable 'c' and 'd' are printed.
Hence the output of the program is -11, 34
Discussion:
20 comments Page 1 of 2.
Vinod Kr. Rai said:
1 decade ago
@arup.
If we write const d=12.34
Then d By default treated as int data type and it store 12
Example:
#include<stdio.h>
int main()
{
const c = 12.34;
const int d = 34;
printf("%d, %d\n", c, d);
return 0;
}
Output:
12, 34
If we write const d=12.34
Then d By default treated as int data type and it store 12
Example:
#include<stdio.h>
int main()
{
const c = 12.34;
const int d = 34;
printf("%d, %d\n", c, d);
return 0;
}
Output:
12, 34
Arafath Iyman said:
1 decade ago
#include<stdio.h>
int main()
{
const c = "araf";
const int d = 34;
printf("%s, %d\n", c, d);
return 0;
}
output : araf, 34
So it c is of any type.
int main()
{
const c = "araf";
const int d = 34;
printf("%s, %d\n", c, d);
return 0;
}
output : araf, 34
So it c is of any type.
Sunil kumar patel said:
1 decade ago
If we write that const d=-12; d will be treated as int data type. By default const is int data type.
Osama Siddiqui said:
6 years ago
I am getting an error: 'c' does not name a type. Can anyone tell me why I am getting this error?
Sarath govind said:
8 years ago
In g++ compiler, it showing error as 'c' was not declared in this scope.
Can anyone help me?
Can anyone help me?
Arup said:
1 decade ago
If we write const d=12.34
Then what will be the output ?
Can anyone help me?
Then what will be the output ?
Can anyone help me?
Amish said:
1 decade ago
In statement const c = -11
c will be declared as what data type ?
And how?
c will be declared as what data type ?
And how?
Ram said:
8 years ago
In C++ Shell compiler, it is treated as an error.
What should I do?
What should I do?
Akshay said:
7 years ago
The const values become int by default, not any one can be default.
XYZ said:
1 decade ago
In statement const c = -11, c will be declared as what data type. ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers