Interview Question
Country: United States
I guess .. following is the issue
you have declared a preprocessor defination of 'a' which depends upon type of array[ ] which you have declared in your subsequent code
The value of preprocessor is substituted before the actual compilation begins. In this case the value of preprocessor can not be determined before compilation hence it takes d=0 while compiling and your for loop does not execute leaving a blank screen
sizeof returns an unsigned integer so when u take d=-1 and cmpare it with the result d<=(a-3) initial value of d changes from -1 to an unsigned value that is 4294967295 which is not less so loop does execute.....
sizeof returns size_t type which is unsigned integer. Comparison between int and unsigned int is unreliable. A warning is generated in gcc if compiled with -Wall. The solution is to cast a to int by (int)a in the for loop.
- suresh.amritapuri June 12, 2012