Question 1
#include <stdio.h>
#define get(s) #s
int main()
{
char str[] = get(GeeksQuiz);
printf("%s", str);
return 0;
}
Question 2
#include <stdio.h>
#if X == 3
#define Y 3
#else
#define Y 5
#endif
int main()
{
printf("%d", Y);
return 0;
}
What is the output of the above program?
3
5
3 or 5 depending on value of X
Compile time error
Question 3
Typically, library header files in C (e.g. stdio.h) contain not only declaration of functions and macro definitions but they contain definition of user defined data types (e.g. struct, union etc), typedefs and definition of global variables as well. So if we include the same header file more than once in a C program, it would result in compile issue because re-definition of many of the constructs of the header file would happen. So it means the following program will give compile error.
#include “stdio.h”
#include “stdio.h”
#include “stdio.h”
int main()
{
printf(“Whether this statement would be printed?”)
return 0;
}
TRUE
FALSE
Question 4
Which file is generated after pre-processing of a C program?
.p
.i
.o
.m
Question 5
What is the use of "#pragma once"?
Used in a header file to avoid its inclusion more than once.
Used to avoid multiple declarations of same variable.
Used in a c file to include a header file at least once.
Used to avoid assertions
Question 6
The translator which performs macro calls expansion is called:
Macro processor
Micro pre - processor
Macro pre - processor
Dynamic Linker
Question 7
What is the output of the following C program?
#include <stdio.h>
#define SQR(x) (x * x)
int main()
{
int a;
int b = 4;
a = SQR(b + 2);
printf("%d", a);
return 0;
}
14
36
18
20
Question 8
Consider the following macro definition:
#define hypotenuse(a, b) (sqrt((a) * (a) + (b) * (b)))What does the following macro call compute?
hypotenuse(a + 2, b + 3)Finds the hypotenuse of a right triangle with sides a + 2 and b + 3
Finds the square root of (a + 2)² and (b + 3)² separately2 and (b+3)2
Is invalid because expressions cannot be passed as macro arguments
Computes sqrt(3*a + 4*b + 5)
Question 9
#include "stdio.h"
#define MYINC ( a ) ( ( a ) + 1 )
int main()
{
printf("GeeksQuiz!");
return 0;
}
Question 10
#define INC1(a) ((a)+1)
#define INC2 (a) ((a)+1)
#define INC3( a ) (( a ) + 1)
#define INC4 ( a ) (( a ) + 1)
There are 21 questions to complete.