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;
}
Error
-11, 34
11, 34
None of these
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.

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?

Chandradeep S said:   7 years ago
In GCC, its's printing some garbage value.

Akshay said:   7 years ago
The const values become int by default, not any one can be default.

Saravana kumar said:   7 years ago
In c++ shell compiler. It shows an error.

Nakul said:   8 years ago
Why only int and what is constant exactly?

Sarath govind said:   8 years ago
In g++ compiler, it showing error as 'c' was not declared in this scope.

Can anyone help me?

Ram said:   8 years ago
In C++ Shell compiler, it is treated as an error.

What should I do?

Ram said:   8 years ago
How it will take int data type?

G Pavan Kumar said:   9 years ago
7 24 [Error] 'c' was not declared in this scope.

Sandeep said:   9 years ago
It is giving error C does not name a type.


Post your comments here:

Your comments will be displayed after verification.