C Programming :: C Preprocessor

Home > C Programming > C Preprocessor > General Questions

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

1 / 33

 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;
}

A3

B4

C12

D0

ECompilation Error

Answer: Option B

Explanation:

Since, using directive statement the valus of a is less than b which is false condition in the ternery statement results to B value.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

2 / 33

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

#include
#define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr());
}

AGarbage Value

BBlank

C100

DCompilation error

ENone of these

Answer: Option C

Explanation:

Preprocessor executes as a seperate pass before the execution of the
compiler. So textual replacement of clrscr() to 100 occurs.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

3 / 33

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

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

Asizeof(i)=2

Bsizeof(i)=1

Csizeof(i)=4

DCompilation error

ENone of these

Answer: Option B

Explanation:

The #define replaces the string int by the macro char

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

4 / 33

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

#include
#define a 10
void main()
{
#define a 50
printf("%d",a);
}

AGarbage Value

BCompilation error

C50

DNone of these

Answer: Option C

Explanation:

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

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

5 / 33

 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);
}

A64

B4

CCompilation error

DNone of these

Answer: Option A

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

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

6 / 33

 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");
}

AFALSE

BTRUE

CCompilation error

DNone of these

Answer: Option B

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

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

7 / 33

 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;
}

A10

B100

CGarbage Value

DCompilation error

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

8 / 33

 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));
}

A10

B12

C19

D9

ENone of these

Answer: Option A

Explanation:

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

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

9 / 33

 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);
}

A0

BGarbage Value

CCompiler error : undefined symbol some

DNone of these

Answer: Option C

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

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

10 / 33

 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);
}

ACompiler error : undefined symbol some

B0 0

CGarbage Value

DNone of these

Answer: Option B

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