Softchoice Interview Question
Software Engineer / DevelopersBecause sizeof is defined as "unsigned int". So a comparison between -1 & sizeof, -1 will be promoted to a unsigned quantity. As a result of which -1 becomes greater then 7.
any integer is automatically converetd to unsigned int (see ritchi page no:197)
suppose int size is 2 bytes
-1=1111111111111111
5=0000000000000101
so when -1 is compared with 5 it converted to unsigned(1111111111111111)2^15-1
which is greater than 5..
thats why no output
If this is the case ....... then why is
for(i=-1;i<5;i++)
printf("Hello World \n");
giving output ??
No output
- Anonymouse March 06, 2011But why i dont know
if change intializer change to d=0,then it will give output.