Why the below program gives the output :A.
what is use of \n after the format specifier %d?
I have tried it on Linux, Windows and ideone.
#include <stdio.h>
int main(void)
{
char p[]="%d\n";
p[1]='c';
printf(p,65);
return 0;
}
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.
First, your program modifies the format string: it becomes “%c\n”. Then it prints 65, which is re-interpreted as an ASCII code, which is an upper-case
A.This is identical to
or even
because
charvalues are converted tointwhen passed to variadic functions such asprintf.