C program Strings Example how come the result is 98? -


c program strings example how come result 98?

 #include <stdio.h> int main()   {   char s[]="%d%d%d";    int a=9,b=8,c=5;      printf(s+2,a,b,c);     return 0;      } 

string + x operation called pointer arithmetic. way providing reference mathematically calculated memory area , semantics equivalent &string[x] happens behind calculation: (&string + (x * sizeof(*string))) why specific notion when applied pointers. stands arrays decay pointer first element after all.


as code, have following string:

char s[]="%d%d%d"; 

and passed format string printf, 2 bytes afterwards, explicitly provides reference "%d%d"


therefore this:

printf(s+2,a,b,c); 

is later parsed as:

printf("%d%d",a,b,c); 

printf except 2 integers read , 3rd 1 - ignored.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -