C Preprocessor
Name: _____________________
Date: _____________________
Instructions: Answer all questions. Write your answers clearly in the space provided.
What is the purpose of the C preprocessor in C programming?
Which directive is used to include the contents of another file in a C program using the C preprocessor?
What is the purpose of the #define directive in C preprocessing?
In C, which directive is used to conditionally include code based on preprocessor macros?
What is the result of the #ifdef DEBUG directive if the DEBUG macro is defined?
Which directive in C preprocessing is used to define a macro with parameters?
In C preprocessing, what is the purpose of the #undef directive?
What does the #ifndef directive do in C preprocessing?
In C, what does the #pragma directive do in C preprocessing?
What is the purpose of the #include directive in C preprocessing?
The preprocessor directive used to give additional information to the compiler, beyond which is conveyed in the language . . . . . . . .
Which of the following operators is used to concatenate two strings without space?
#pragma GCC poison should be followed by a list of identifiers that are . . . . . . . .
In the directive, #pragma pack(n), which of the following is not a valid value of n?
Which of the following is a stringizing operator?
The pragma . . . . . . . . is used to remove an identifier completely from a program.
Which of the following attributes is used to specify that the minimum required memory to be used to represent the types?
In C, how do you use the #ifndef directive to conditionally include code if a macro is not defined?
What does the #pragma once directive do in C preprocessing?
In C, what is the purpose of the #ifdef directive?
What is the purpose of the #pragma warning directive in C preprocessing?
In C preprocessing, what is the purpose of the #elifdef directive?
What is the result of the #pragma message directive in C preprocessing?
What is the purpose of the #undef directive in C preprocessing?
In C preprocessing, what is the purpose of the #elifndef directive?
What is the result of the #pragma warning directive in C preprocessing?
In C, what is the purpose of the #line directive?
Which of the following is not a preprocessor directive?
The preprocessor directive which is used to remove the definition of an identifier which was previously defined with #define?
The preprocessor directive which checks whether a constant expression results in a zero or non-zero value . . . . . . . .
The purpose of the preprocessor directive #error is that . . . . . . . .
C preprocessor
A preprocessor command
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.
In which stage the following code #include<stdio.h> gets replaced by the contents of the file stdio.h
. . . . . . . . is the preprocessor directive which is used to end the scope of #ifdef.
In the directive #pragma pack(n), if the value of 'n' is given to be 5, then what happens?
What is the purpose of the #if directive in C preprocessing?
In C, how do you use the #ifdef directive to conditionally include code if a macro is defined?
What is the purpose of the #error directive in C preprocessing?
What is the result of the #ifndef DEBUG directive if the DEBUG macro is defined?
Which directive in C preprocessing is used to concatenate two or more strings?
In C, what does the #line directive do in C preprocessing?
What is the purpose of the #pragma once directive in C preprocessing?
In C preprocessing, what is the purpose of the #elif directive?
What is the result of the #error directive in C preprocessing?
What is the purpose of the #pragma message directive in C preprocessing?
What will be the output of the following C code? #include<stdio.h>
#define max 100
main()
{
#ifdef max
printf("hello")
}
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)
}
The function of __attribute__((packed))
can also be performed using . . . . . . . .
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)
}
What will be the output of the following C code? #define HELLO(a) #a
main()
{
printf(HELLO(good morning))
}
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)
}
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))
}
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)
}
What will be the output of the program code? #include<stdio.h>
#define a 10
void main()
{
#define a 50
printf("%d", a)
}
Determine output: #include<stdio.h>
#define clrscr() 100
void main()
{
clrscr()
printf("%dn", clrscr())
}
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))
}
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++)
}
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
}
The output of the following program is: #define f(g,g2) g##g2
void main()
{
int var12=100
printf("%d", f(var,12))
}
Find the output of the following program. #define INC(X) X++
void main()
{
int x=4
printf("%d", INC(x++))
}
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)
}
What will be the output of the following C code? #define display(text) "$" #text
main()
{
printf(display(hello world))
}
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
}
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")
}
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
}
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
}
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)
}
What will be the output of the following C code? #define hello(c) #c
main()
{
printf(hello(i,am))
}
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")
}
The correct syntax of the attribute packed is . . . . . . . .
What will be the output of the following C code? #define hello(c,d) #c #d
main()
{
printf(hello(i,"am"))
}
What will be the output of the following C code? #define display(a) #a
main()
{
printf(display("56#7"))
}
What will be the output of the following C code? #include<stdio.h>
#pragma GCC poison printf
main()
{
printf("example")
return 0
}
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))
}
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)
}
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)
}
What will be the output of the following C code? #include<stdio.h>
void main()
{
#ifndef max
printf("hello")
#endif
printf("hi")
}
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)
}
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)
}
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)
}
What will be the output of the following C code? #define example(s,n) #s #n
main()
{
printf(example(hello,world))
}
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")
}
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)
}
What will be the output of the following C code? #define display(text) printf(#text "@")
main()
{
display(hello.)
display(good morning!)
}
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)
}
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)
}
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)
}
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)
}
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)
}
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
}
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)
}
Answer Key
{ 100
printf ( " %d
", 100 )
} Note: 100
is an executable statement but with no action. So it doesn't give any problem.