Discussion :: C-MCQs
-
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");
}
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
Explanation :
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
Be The First To Comment