output :- me is DweCode:#include<stdio.h>
int main ()
{
printf(5+"My name is Dwe");
return 0;
}
Please anyone help me . Explain because printf function print the "" field string and it is eating 5 words of string
thank you
Printable View
output :- me is DweCode:#include<stdio.h>
int main ()
{
printf(5+"My name is Dwe");
return 0;
}
Please anyone help me . Explain because printf function print the "" field string and it is eating 5 words of string
thank you
Printf format strings - Cprogramming.com
What is "5+" supposed to be doing?Code:printf(5+"My name is Dwe");
That's what I am asking that What it is doing :P . Please explain anyone
Hint: if x is an array, then x[5] is equivalent to *(x + 5), which is equivalent to *(5 + x).
This question from pointers:eek: . ???
Yes, it is. The array, in this case a string literal, is converted to a pointer to its first element. So, when you add 5 to a pointer, what happens?
Actually I am a beginner .I just started reading C . So i don't have any idea about pointers and arrays. I saw this problem and I get confused with printf function . Thanks for reply
Okay. Then you can ignore this until later, or just accept that adding 5 skips the first 5 characters of the string to be printed.
Okay, let's say that the string literal "My name is Dwe\0" is stored at the memory address 0x100. Printf, when using %s, will print characters starting at the location provided until it hits a zero. It would do this:
0x100 | 'M'
0x101 | 'y'
.....
0x10d | 'e'
0x10e | '\0' <-- and it stops printing.
However, adding five would make it start printing at 0x105:
0x105 | 'm'
0x106 | 'e'
0x107 | ' '
.....