Sail E0 Webinar
Question
What is the output of this C code?
void main()
{
int k = 4;
float k = 4;
printf("%d", k)
}
Options:
A .  Compile time error
B .  4
C .  4.0000000
D .  4.4
Answer: Option A


Since the variable k is defined both as integer and as float, it results in an error.
Output:
$ cc pgm8.c
pgm8.c: In function 'main':
pgm8.c:5: error: conflicting types for 'k'
pgm8.c:4: note: previous definition of 'k' was here
pgm8.c:6: warning: format '%d' expects type 'int', but argument 2 has type 'double'
pgm8.c:7: error: expected ';' before '}' token



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers