Tuesday, July 14, 2009

C mysteries??

#include%26lt;stdio.h%26gt;


void main()


{


printf("%d%c");


}





the output of te program is


0 and X


how is it possible??





if you have programs like this sort ,plzz write in!i would love 2 know more!!!

C mysteries??
In your printf("%d%c");


you do not specify any variables or data to be printed.


Printf() "pretends" there is data anyway and prints it out (what the 0 and X are is whatever is on the stack at the time - return addresses usually).





try printf("%d%c", 123, 88 );
Reply:I think it can print anything. Since you have not specifed the format string properly, and these are the (were) major causes of vulnerability in server applications.


Printf() function will first read string and understand the format what to print and then will go on to read the data to print in that exact format specified. Since you have not provided the data/variable it will go in to the next address (pointer) to pick the data and for that it is going to print the garbage which is present there at that time.


I think its not necessary that it print 0 and X every time, across every platform/c-compiler.


No comments:

Post a Comment