int main()
{
int i,j;
i='c';
scanf("%d",&j); // I will read 'c' here
printf("%d %d",i,j);
}
Output is not same.'j' takes garbage value and 'i' takes ascii value of 'c'. Can anybody tell what could be the reason ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You
scanfsays:With this sentence
scanfwill try to parse (convert) the ‘c’ character you are using as input to the function into a number. That’s way you get garbage. C doesn’t know how to turn ‘c’ into a number, becausescanfis expecting digits.Try changing that to:
If your
printfcall is like this:You should get the same value, both times: ASCII value of ‘c’ character.