I am a novice for C language.but I could understand why this
following code is giving output as ‘A’.
one thing that is bothering me is the array name p in the
printf statement.how this p is being treated by the compiler?
How can the p is replaced by the character array “%c\n” after line no 5?
I know that this is a silly question so sorry to post this hare.
Can anyone will help me to understand the concept behind this?
line1: #include<stdio.h>
line2: int main()
line3: {
line4: char p[]="%d\n";
line5: p[1]='c';
line6: printf(p,65);
line7: return 0;
}
The first argument to
printf()is aconst char*that contains the format specifiers. It is more common to see it as a string literal:but it is legal to use a variable containing a string.
The assignment of
p[1] = 'c'changes thedtocin the bufferp, resulting in the characterA(as65is decimal value forA) being written to standard output (as%cinstructsprintf()to print the character, rather than%dwhich will print the numeric value).