Is a = getchar() equivalent to scanf("%c",&a);?
Is putchar(a) equivalent to printf("%c",a); where a is a char variable?
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.
Generally speaking yes they are the same.
But they are not in a few nitpicky ways. The function
getcharis typed to returnintand notchar. This is done so thatgetcharcan both all possiblecharvalues and additionally error codes.So while the following happily compiles in most compilers you are essentially truncating away an error message
The function
scanf, though, allows you to use achartype directly and separates out the error code into the return value.