C Preprocessor

Name: _____________________

Date: _____________________

Instructions: Answer all questions. Write your answers clearly in the space provided.

Question 1:

What is the purpose of the C preprocessor in C programming?

A. Compile C code
B. Optimize code
C. Preprocess code before compilation
D. Execute code
Answer: _________
Question 2:

Which directive is used to include the contents of another file in a C program using the C preprocessor?

A. #define
B. #include
C. #ifdef
D. #pragma
Answer: _________
Question 3:

What is the purpose of the #define directive in C preprocessing?

A. To include a header file
B. To define a macro
C. To declare a constant
D. To declare a variable
Answer: _________
Question 4:

In C, which directive is used to conditionally include code based on preprocessor macros?

A. #ifdef
B. #ifndef
C. #if
D. #else
Answer: _________
Question 5:

What is the result of the #ifdef DEBUG directive if the DEBUG macro is defined?

A. The code block following it is included
B. The code block following it is excluded
C. It generates a compilation error
D. It defines the DEBUG macro
Answer: _________
Question 6:

Which directive in C preprocessing is used to define a macro with parameters?

A. #define
B. #ifdef
C. #include
D. #if
Answer: _________
Question 7:

In C preprocessing, what is the purpose of the #undef directive?

A. To undefine a macro
B. To include a header file
C. To define a macro
D. To declare a variable
Answer: _________
Question 8:

What does the #ifndef directive do in C preprocessing?

A. Checks if a macro is defined
B. Checks if a macro is not defined
C. Checks if a variable is declared
D. Checks if a function is defined
Answer: _________
Question 9:

In C, what does the #pragma directive do in C preprocessing?

A. Includes a header file
B. Provides compiler-specific instructions
C. Defines a macro
D. Checks for syntax errors
Answer: _________
Question 10:

What is the purpose of the #include directive in C preprocessing?

A. To define a macro
B. To include a header file
C. To declare a variable
D. To conditionally compile code
Answer: _________
Question 11:

The preprocessor directive used to give additional information to the compiler, beyond which is conveyed in the language . . . . . . . .

A. #include
B. #define
C. #pragma
D. #elif
Answer: _________
Question 12:

Which of the following operators is used to concatenate two strings without space?

A. #
B. < >
C. **
D. ##
Answer: _________
Question 13:

#pragma GCC poison should be followed by a list of identifiers that are . . . . . . . .

A. even in number
B. odd in number
C. valid
D. invalid
Answer: _________
Question 14:

In the directive, #pragma pack(n), which of the following is not a valid value of n?

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 15:

Which of the following is a stringizing operator?

A. < >
B. #
C. %
D. ##
Answer: _________
Question 16:

The pragma . . . . . . . . is used to remove an identifier completely from a program.

A. GNU piston
B. GCC poison
C. GNU poison
D. GCC piston
Answer: _________
Question 17:

Which of the following attributes is used to specify that the minimum required memory to be used to represent the types?

A. packed
B. aligned
C. unused
D. deprecated
Answer: _________
Question 18:

In C, how do you use the #ifndef directive to conditionally include code if a macro is not defined?

A. #ifndef MACRO
B. #ifndef(MACRO)
C. #ifndef:MACRO
D. #ifndef: MACRO
Answer: _________
Question 19:

What does the #pragma once directive do in C preprocessing?

A. Prevents multiple inclusion of header files
B. Defines a macro
C. Checks for syntax errors
D. Excludes code
Answer: _________
Question 20:

In C, what is the purpose of the #ifdef directive?

A. Checks if a macro is defined
B. Checks if a macro is not defined
C. Defines a macro
D. Includes a header file
Answer: _________
Question 21:

What is the purpose of the #pragma warning directive in C preprocessing?

A. Generates a warning message
B. Defines a macro
C. Checks for syntax errors
D. Excludes code
Answer: _________
Question 22:

In C preprocessing, what is the purpose of the #elifdef directive?

A. Checks if a macro is defined
B. Checks if a macro is not defined
C. Provides an alternative condition
D. Defines a macro
Answer: _________
Question 23:

What is the result of the #pragma message directive in C preprocessing?

A. Includes a message in the code
B. Defines a macro
C. Checks for syntax errors
D. Excludes code
Answer: _________
Question 24:

What is the purpose of the #undef directive in C preprocessing?

A. Undefines a macro
B. Defines a macro
C. Checks for syntax errors
D. Excludes code
Answer: _________
Question 25:

In C preprocessing, what is the purpose of the #elifndef directive?

A. Checks if a macro is defined
B. Checks if a macro is not defined
C. Provides an alternative condition
D. Defines a macro
Answer: _________
Question 26:

What is the result of the #pragma warning directive in C preprocessing?

A. Generates a warning message
B. Defines a macro
C. Checks for syntax errors
D. Excludes code
Answer: _________
Question 27:

In C, what is the purpose of the #line directive?

A. Specifies the line number and filename in the source file
B. Defines a macro
C. Checks for syntax errors
D. Excludes code
Answer: _________
Question 28:

Which of the following is not a preprocessor directive?

A. #error
B. #pragma
C. #if
D. #ifelse
Answer: _________
Question 29:

The preprocessor directive which is used to remove the definition of an identifier which was previously defined with #define?

A. #ifdef
B. #undef
C. #ifndef
D. #def
Answer: _________
Question 30:

The preprocessor directive which checks whether a constant expression results in a zero or non-zero value . . . . . . . .

A. #if
B. #ifdef
C. #undef
D. #ifndef
Answer: _________
Question 31:

The purpose of the preprocessor directive #error is that . . . . . . . .

A. It rectifies any error present in the code
B. It rectifies only the first error which occurs in the code
C. It causes the preprocessor to report a fatal error
D. It causes the preprocessor to ignore an error
Answer: _________
Question 32:

C preprocessor

A. Takes care of conditional compilation
B. Takes care of macros
C. Takes care of include files
D. Acts before compilation
Answer: _________
Question 33:

A preprocessor command

A. need not start on a new line
B. need not start on the first column
C. has # as the first character
D. comes before the first executable statement
Answer: _________
Question 34:

Choose the correct statement. I.xa0xa0xa0The scope of a macro definition need not be the entire program. II.xa0xa0The scope of a macro definition extends from the point of definition to the end of the file. III.xa0New line is a macro definition delimiter. IV.xa0xa0A macro definition may go beyond a line.

A. I and II
B. II and III
C. I, II and III
D. II, III and IV
Answer: _________
Question 35:

In which stage the following code #include<stdio.h> gets replaced by the contents of the file stdio.h

A. During Preprocessing
B. During Execution
C. During linking
D. During Editing
Answer: _________
Question 36:

. . . . . . . . is the preprocessor directive which is used to end the scope of #ifdef.

A. #elif
B. #ifndef
C. #endif
D. #if
Answer: _________
Question 37:

In the directive #pragma pack(n), if the value of 'n' is given to be 5, then what happens?

A. Error
B. Warning but no error
C. Executes the pragma statement
D. Ignores the pragma statement and executes the program
Answer: _________
Question 38:

What is the purpose of the #if directive in C preprocessing?

A. To check if a variable is declared
B. To conditionally include code
C. To include a header file
D. To define a macro
Answer: _________
Question 39:

In C, how do you use the #ifdef directive to conditionally include code if a macro is defined?

A. #ifdef MACRO
B. #ifdef(MACRO)
C. #ifdef:MACRO
D. #ifdef: MACRO
Answer: _________
Question 40:

What is the purpose of the #error directive in C preprocessing?

A. To include an error message in the code
B. To define a macro
C. To check if a variable is declared
D. To conditionally compile code
Answer: _________
Question 41:

What is the result of the #ifndef DEBUG directive if the DEBUG macro is defined?

A. The code block following it is included
B. The code block following it is excluded
C. It generates a compilation error
D. It defines the DEBUG macro
Answer: _________
Question 42:

Which directive in C preprocessing is used to concatenate two or more strings?

A. #concat
B. #strcat
C. #combine
D. #define
Answer: _________
Question 43:

In C, what does the #line directive do in C preprocessing?

A. Specifies the line number in the source file
B. Defines a macro
C. Includes a header file
D. Excludes code
Answer: _________
Question 44:

What is the purpose of the #pragma once directive in C preprocessing?

A. Prevents recursive inclusion of header files
B. Defines a macro
C. Checks for syntax errors
D. Excludes code
Answer: _________
Question 45:

In C preprocessing, what is the purpose of the #elif directive?

A. Checks if a macro is defined
B. Checks if a macro is not defined
C. Provides an alternative condition
D. Defines a macro
Answer: _________
Question 46:

What is the result of the #error directive in C preprocessing?

A. Generates a compilation error with a specified error message
B. Defines a macro
C. Checks for syntax errors
D. Excludes code
Answer: _________
Question 47:

What is the purpose of the #pragma message directive in C preprocessing?

A. Includes a message in the code
B. Defines a macro
C. Checks for syntax errors
D. Excludes code
Answer: _________
Question 48:

What will be the output of the following C code? #include<stdio.h>
#define max 100
main()
{
#ifdef max
printf("hello")
}

A. 100
B. hello
C. "hello"
D. error
Answer: _________
Question 49:

What will be the output of the following C code? #include<stdio.h>
#define hello 10
main()
{
#ifdef hello
#undef hello
#define hello 100
#else
#define hello 200
#endif
printf("%d",hello)
}

A. Error
B. 10
C. 100
D. 200
Answer: _________
Question 50:

The function of __attribute__((packed))
can also be performed using . . . . . . . .

A. #pragma pack(1)
B. #pragma pack(2)
C. #pragma pack(4)
D. #pragma pack(8)
Answer: _________
Question 51:

What will be the output of the following C code? #include<stdio.h>
void f()
{
#define sf 100
printf("%d",sf)
}
int main()
{
#define sf 99
f()
printf("%d",sf)
}

A. error
B. 100
C. 99
D. 10099
Answer: _________
Question 52:

What will be the output of the following C code? #define HELLO(a) #a
main()
{
printf(HELLO(good morning))
}

A. good xa0xa0xa0xa0xa0xa0 morning
B. HELLO good morning
C. good morning
D. error
Answer: _________
Question 53:

What will be the output of the following C code? #include<stdio.h>
#define ram 10
main()
{
#ifdef ram
#define ram 20
#endif
printf("%d",ram)
}

A. 10
B. 20
C. Error
D. 1020
Answer: _________
Question 54:

What will be the output of the program? #include<stdio.h>
#define int char
void main()
{
int i = 65
printf("sizeof(i)=%d", sizeof(i))
}

A. sizeof(i)=2
B. sizeof(i)=1
C. Compiler Error
D. None of These
Answer: _________
Question 55:

What will be the output of the following program? #include<stdio.h>
#define square(x) x*x
void main()
{
int i
i = 64/square(4)
printf("%d", i)
}

A. 4
B. 64
C. 16
D. None of These
Answer: _________
Question 56:

What will be the output of the program code? #include<stdio.h>
#define a 10
void main()
{
#define a 50
printf("%d", a)
}

A. 50
B. 10
C. Compiler Error
D. None of These
Answer: _________
Question 57:

Determine output: #include<stdio.h>
#define clrscr() 100
void main()
{
clrscr()
printf("%dn", clrscr())
}

A. 0
B. 1
C. 100
D. Error
Answer: _________
Question 58:

What will be the output of the following program? #include<stdio.h>
#define prod(a,b) a*b
void main()
{
int x=3,y=4
printf("%d", prod(x+2,y-1))
}

A. 15
B. 12
C. 10
D. 11
Answer: _________
Question 59:

What will be output if you will compile and execute the following c code? #include<stdio.h>
#define max 5
void main(){
int i = 0
i = max++
printf("%d", i++)
}

A. 5
B. 6
C. 7
D. 0
Answer: _________
Question 60:

What will be output after executing following code? #include<stdio.h>
# define a 10
void main()
{
printf("%d..", a)
foo()
printf("%d", a)
}
void foo()
{
#undef a
#define a 50
}

A. 10..50
B. 10..10
C. 0
D. Error
Answer: _________
Question 61:

The output of the following program is: #define f(g,g2) g##g2
void main()
{
int var12=100
printf("%d", f(var,12))
}

A. Syntax error
B. Runtime error
C. g##g2
D. 100
Answer: _________
Question 62:

Find the output of the following program. #define INC(X) X++
void main()
{
int x=4
printf("%d", INC(x++))
}

A. 4
B. 5
C. 6
D. Error
Answer: _________
Question 63:

What will be the output of the following C code? #include<stdio.h>
#define max 20
main()
{
#ifndef max
#define min 10
#else
#define min 30
#endif
printf("%d",min)
}

A. 10
B. 20
C. 30
D. error
Answer: _________
Question 64:

What will be the output of the following C code? #define display(text) "$" #text
main()
{
printf(display(hello world))
}

A. hello world
B. $helloworld
C. $hello world
D. error
Answer: _________
Question 65:

What will be the output of the following C code? #include <stdio.h>
#define Shyam(x) #x
int main()
{
int marks=100
printf("value of %s is = %d
",Shyam(marks),marks)
return 0
}

A. error
B. value of marks=100
C. value of=100
D. 100
Answer: _________
Question 66:

What will be the output of the following C code? #include<stdio.h>
#define max 100
void main()
{
#if(max%10)
printf("Exam")
#endif
printf("Veda")
}

A. error
B. Exam
C. Veda
D. ExamVeda
Answer: _________
Question 67:

What will be the output of the following C code? #include<stdio.h>
#define INDIA 1
#define US 2
#define CC US
main()
{
#if CC==INDIA
printf("Rupee")
#elif CC==US
printf("Dollar")
#else
printf("Euro")
#endif
}

A. Euro
B. Rupee
C. Dollar
D. Error
Answer: _________
Question 68:

What will be the output of the following C code if the value of 'p' is 10 and that of 'q' is 15? #include<stdio.h>
int main()
{
int p,q
printf("Enter two numbers
")
scanf("%d",&p)
scanf("%d",&q)
#if(4<2)
printf("%d",p)
#elif(2>-1)
printf("%d",q)
#else
printf("bye")
#endif
}

A. 10
B. 15
C. bye
D. error
Answer: _________
Question 69:

What will be the output of the following C code? #include <stdio.h>
#define p( n ) printf( "t" #n " = %d", t##n )
int t3=10
int main()
{
p(3)
}

A. t=10
B. t3=10
C. t10=3
D. t=3
Answer: _________
Question 70:

What will be the output of the following C code? #define hello(c) #c
main()
{
printf(hello(i,am))
}

A. i,am
B. iam
C. i am
D. error
Answer: _________
Question 71:

What will be the output of the following C code? #include<stdio.h>
#define ram 557
int main()
{
#ifndef ram
printf("yes")
#endif
printf("no")
}

A. error
B. yes
C. no
D. yesno
Answer: _________
Question 72:

The correct syntax of the attribute packed is . . . . . . . .

A. __attribute__((packed))
B. _attribute(packed)
C. _attribute_((packed))
D. __attribute__(packed)
Answer: _________
Question 73:

What will be the output of the following C code? #define hello(c,d) #c #d
main()
{
printf(hello(i,"am"))
}

A. iam
B. i"am"
C. am
D. "am"
Answer: _________
Question 74:

What will be the output of the following C code? #define display(a) #a
main()
{
printf(display("56#7"))
}

A. Error
B. "56#7"
C. 56#7
D. 567
Answer: _________
Question 75:

What will be the output of the following C code? #include<stdio.h>
#pragma GCC poison printf
main()
{
printf("example")
return 0
}

A. error is thrown
B. example is printed
C. warning but no error
D. pleexam is printed
Answer: _________
Question 76:

What will be the output of the following C code, if it is run on a 32 bit platform? #include<stdio.h>
#pragma(1)
struct test
{
int i
char j
}
main()
{
printf("%d",sizeof(struct test))
}

A. Error
B. 1
C. 4
D. 8
Answer: _________
Question 77:

What will be the output of the following C code? #include <stdio.h>
#define p( m ) printf( "t*" #m " = %s", t##m )
char tram[]="tram"
int main()
{
int x
x=p(ram)
}

A. error
B. tram=tram
C. t*ram=t*ram
D. t*ram=tram
Answer: _________
Question 78:

What will be the output of the following C code? #include<stdio.h>
#define sf 10
main()
{
if(sf==100)
printf("good")
else
{
printf("bad")
sf=100
}
printf("%d",sf)
}

A. 100
B. bad
C. 10
D. error
Answer: _________
Question 79:

What will be the output of the following C code? #include<stdio.h>
void main()
{
#ifndef max
printf("hello")
#endif
printf("hi")
}

A. hello
B. hellohi
C. error
D. hi
Answer: _________
Question 80:

The following C code results in an error. #include <stdio.h>
#define world( n ) printf( "t^^" #n" = %c", t##n )
int t3=1
int main()
{
world(3)
}

A. True
B. False
Answer: _________
Question 81:

What will be the output of the following C code? #define F abc
#define B def
#define FB(arg) #arg
#define FB1(arg) FB(arg)
main()
{
printf(FB(F B))
FB1(F B)
}

A. F B
B. Error
C. FB
D. "FB"
Answer: _________
Question 82:

What will be the output of the following C code? #include <stdio.h>
#define p( n,m ) printf( "%d", m##n )
int main()
{
p(3,4)
}

A. Error
B. Junk value
C. 34
D. 43
Answer: _________
Question 83:

What will be the output of the following C code? #define example(s,n) #s #n
main()
{
printf(example(hello,world))
}

A. example(hello,world)
B. example
C. hello,world
D. helloworld
Answer: _________
Question 84:

What will be the output of the following C code? #include <stdio.h>
#define hello( n ) a##n
int a3
int main()
{
int x
x=hello(3)
if(x!=0)
printf("hi")
else
printf("good")
}

A. error
B. a3
C. good
D. hi
Answer: _________
Question 85:

What will be the output of the following C code? #include<stdio.h>
#define hello
main()
{
#ifdef hello
#define hi 4
#else
#define hi 5
#endif
printf("%d",hi)
}

A. 4
B. 5
C. 45
D. error
Answer: _________
Question 86:

What will be the output of the following C code? #define display(text) printf(#text "@")
main()
{
display(hello.)
display(good morning!)
}

A. hello.@good morning!
B. error
C. hello.good morning!@
D. hello.@good morning!@
Answer: _________
Question 87:

What will be the output of the following C code? #include <stdio.h>
#define p( n ) printf( "t%%
" #n " = %d", t##n )
int t3=10
int main()
{
int x
x=p(3)
}

A. t% 3=10
B. t3=10
C. t%3=10
D. t %3=10
Answer: _________
Question 88:

What will be the output of the following C code? #include <stdio.h>
#define p( n,m ) printf( "%d", m##n )
#define q(a,b) printf("%d",a##b)
main()
{
p(3,4)
q(5,6)
}

A. 4356
B. 3456
C. 4365
D. 3465
Answer: _________
Question 89:

What will be the output of the following C code? #include<stdio.h>
#define hello 10
void main()
{
printf("%d",hello)
#undef hello
printf("%d",hello)
}

A. 10
B. hello
C. error
D. 1010
Answer: _________
Question 90:

What will be the output of the following C code? #include <stdio.h>
#define display( n ) printf( "a" #n " = %d", a##n )
int main()
{
display(3)
}

A. a3
B. 31
C. a 3
D. error
Answer: _________
Question 91:

What will be the output of the following C code? #include <stdio.h>
#define a 2
main()
{
int r
#define a 5
r=a*2
printf("%d",r)
}

A. 10
B. 4
C. 2
D. 5
Answer: _________
Question 92:

What will be the output of the following C code? #include <stdio.h>
#define hello( n ) printf( "a" #n "= %d", a##n )
int a3=3
int main()
{
#ifdef a3
hello(3)
#else
printf("sorry")
#endif
}

A. a3=3
B. error
C. a=3
D. sorry
Answer: _________
Question 93:

What will be the output of the following C code? #define sqr(x) x*x
main()
{
int a1
a1=25/sqr(5)
printf("%d",a1)
}

A. 25
B. 1
C. 5
D. error
Answer: _________

Answer Key

1: C
2: B
3: B
4: C
5: A
6: A
7: A
8: B
9: B
10: B
11: C
12: D
13: D
14: C
15: B
16: B
17: A
18: A
19: A
20: A
21: A
22: C
23: A
24: A
25: B
26: A
27: A
28: D
29: B
30: A
31: C
32: N/A
33: C
34: N/A
35: A
36: C
37: D
38: B
39: A
40: A
41: B
42: D
43: A
44: A
45: C
46: A
47: A
48: D
49: C
50: A
51: A
52: C
53: B
54: B
Solution: Since the #define replaces the string int by the macro char . So, here i is a variable of type char and not int .
55: B
Solution: The macro call square(4) will be substituted by 4*4 so the expression becomes i = 64/4*4 . Since / and * has equal priority and associativity left to right, so the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64.
56: A
Solution: The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken.
57: C
Solution: 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 : void main ()
{ 100
printf ( " %d
", 100 )
} Note: 100
is an executable statement but with no action. So it doesn't give any problem.
58: C
Solution: The macro expands and evaluates to as: x+2*y-1 => x+(2*y)-1 => 10
59: N/A
Solution: main.c: In function ‘main’: main.c:5:12: error: lvalue required as increment operand i = max++
60: B
61: D
Solution: ## is token pasting operator which simply combines all the parameters of macro into one variable. So, in f(var, 12), var and 12 combines to form var12 and replaces the f(var, 12) and hence the output is 100.
62: D
Solution: L value is required for this expression (x++) which is illegal.
63: C
64: C
65: B
66: C
67: C
68: B
69: B
70: D
71: C
72: A
73: B
74: B
75: A
76: D
77: D
78: D
79: B
80: B
81: A
82: D
83: D
84: C
85: A
86: D
87: A
88: A
89: C
90: D
91: A
92: D
93: A