What will be the output of the following C code?
#include <stdio.h>
void main()
{
int x = 97;
char y = x;
printf("%c\n", y);
}
#include <stdio.h>
void main()
{
int x = 97;
char y = x;
printf("%c\n", y);
}
A. a
B. b
C. 97
D. Run time error
Answer: Option A
Solution (By Examveda Team)
1. Declaration:int x = 97;
2. Conversion:
char y = x;
3. ASCII Value: The ASCII value of
97
corresponds to the character 'a'
.4. Print:
printf("%c\n", y);
prints the character 'a'
.
Value of the ASCII a is 97 so as per statement y=x and x=97 ,
here
x=97
y=x
97=a (ASCII table)