Sail E0 Webinar
Question
Comment on the output of this C code?
int main()
{
int a[5] = {1, 2, 3, 4, 5};
int i;
for (i = 0; i < 5; i++)
if ((char)a[i] == '5')
printf("%d\n", a[i]);
else
printf("FAIL\n");
}
Options:
A .  The compiler will flag an error
B .  Program will compile and print the output 5
C .  Program will compile and print the ASCII value of 5
D .  Program will compile and print FAIL for 5 times
Answer: Option D


The ASCII value of 5 is 53, the char type-casted integral value 5 is 5 only.
Output:
$ cc pgm1.c
$ a.out
FAILED
FAILED
FAILED
FAILED
FAILED



Was this answer helpful ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers