Monday 19 December 2011

Predict the output or error(s) for the following:

1)

#include <stdio.h>

#define a 10

main()

{

#define a 50


printf("%d",a);


}

Answer:

50


Explanation:

The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken.


2)

#define clrscr() 100

main()

{

clrscr();


printf("%d\n",clrscr());


}

Answer:

100


Explanation:

Preprocessor executes as a seperate pass before the execution of the compiler. So textual replacement of clrscr() to 100 occurs.The input  program to compiler looks like this :


        main()

{


100;


printf("%d\n",100);


}


Note:  100; is an executable statement but with no action. So it doesn't give any problem

1 comment: