Saturday, December 30, 2006

string inside scanf()

what will the following statement do???

scanf( " %d %d" + scanf("%d %d",&i,&j) ,&a);

the inner scanf will take two integers as input and storing them in i and j respectively and returning 2.

the outer scanf's expression will now become "%d %d"+2 which will become " %d".... how??? now the expression inside the " " in scanf in considered as a string and is stored in some part of the memory and when we call the scanf function then a pointer to this memory location is passed on to scanf... but in this case the pointer gets incremented by two and thus points to the string " %d" rather than "%d %d", and since the former one is a legitimate expression for scanf the function takes one input in a.

No comments: