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.

XYZ said:   1 decade ago
In statement const c = -11, c will be declared as what data type. ?

Madhusudan said:   1 decade ago
By default it takes int.

Shahrukh said:   1 decade ago
Ya it will take int as the default data 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.

Soumya said:   1 decade ago
Thanks Sunil.

Arup said:   1 decade ago
If we write const d=12.34
Then what will be the output ?
Can anyone help me?

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

Dinesh said:   1 decade ago
What will be the data type of "c"?

Amish said:   1 decade ago
In statement const c = -11
c will be declared as what data type ?
And how?

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.


Post your comments here:

Your comments will be displayed after verification.