Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

C Programming :: C Preprocessor

Home > C Programming > C Preprocessor > General Questions

1. What will be output of the following "c" code?

#include
#define max(a,b) (a>b)? a:b
int main()
{
int a,b; a=3; b=4;
printf("%d",max(a,b));
return 0;
}

Answer: 4

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

2. What will be output of the following "c" code?

#include
#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.

Workspace

Tags:

No Tags on this question yet!

3. What will be output of the following "c" code?

#include
#define int char
void main()
{
int i=65;
printf("sizeof(i)=%d",sizeof(i));
}

Answer: sizeof(i)=1

Explanation:

The #define replaces the string int by the macro char

Workspace

Tags:

No Tags on this question yet!

4. What will be output of the following "c" code?

#include
#define a 10
void 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.

Workspace

Tags:

No Tags on this question yet!

5. What will be output of the following "c" code?

#include
#define square(x) x*x
void main()
{
int i;
i = 64/square(4);
printf("%d",i);
}

Answer: 64

Explanation:

Pre-processor will substitute square(4) by 4*4
so the expression becomes I = 64/4*4 .
Since / and * has equal priority the expression will be evaluated as (64/4)*4 => 16*4 = 64

Workspace

Tags:

No Tags on this question yet!

6. What will be output of the following "c" code?

#include
#define FALSE -1
#define TRUE 1
#define NULL 0
int main() {
if(NULL)
puts("NULL");
else if(FALSE)
puts("TRUE");
else
puts("FALSE");
}

Answer: TRUE

Explanation:

Preprocessor doesn't replace the values given inside the double quotes. The check by if condition is boolean value false so it goes to else. In second if -1 is boolean value true hence "TRUE" is printed.

Workspace

Tags:

No Tags on this question yet!

7. What will be output of the following "c" code?

#include
#define f(g,g2) g##g2
int main()
{
int var12=100;
printf("%d",f(var,12));
return 0;
}

Answer: 100

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

8. What will be output of the following "c" code?

#include
#define prod(a,b) a*b
void main()
{
int x=3,y=4;
printf("%d",prod(x+2,y-1));
}

Answer: 10

Explanation:

The macro expands and evaluates to as:
x+2*y-1
=> x+(2*y)-1
=> 3+(2*4)-1 => 10

Workspace

Tags:

No Tags on this question yet!

9. What will be output of the following "c" code?

#include
#ifdef something
int some=0;
#endif
void main()
{
int thing = 0;
printf("%d %d\n", some ,thing);
}

Answer: Compiler error : undefined symbol some

Explanation:

This is a very simple example for conditional compilation.
The name something is not already known to the compiler making the declaration int some = 0; effectively removed from the source code.

Workspace

Tags:

No Tags on this question yet!

10. What will be output of the following "c" code?

#include
#if something == 0
int some=0;
#endif

void main()
{
int thing = 0;
printf("%d %d\n", some ,thing);
}

Answer: 0 0

Explanation:

This code is to show that preprocessor expressions are not the same as the ordinary expressions. If a name is not known the preprocessor treats it to be equal to zero.

Workspace

Tags:

No Tags on this question yet!