+ 2

why am i not getting output for the first one where as i am getting for second one

in first program i am using scanf to get int where as in second one i am directly assigning 65 to char x then why there is a difference 1) #include <stdio.h> int main() { char x; scanf("%d",&x); printf("%c",x); } 2)#include <stdio.h> int main() { char x=65; printf("%c",x); }

25th Jun 2020, 2:46 PM
S.Brindha
S.Brindha  - avatar
2 Answers
+ 9
1) do scanf("%c",&x); take character input
25th Jun 2020, 2:55 PM
ÃKR
ÃKR - avatar
0
if a program has scanf("%d",&a) when i give character input why cant it take the asccii value of the character which is an int and store it in a instead showing error eg if i give input as A its ascii value 65 can be stored in a why there is an error
22nd Jul 2020, 4:20 PM
S.Brindha
S.Brindha  - avatar