[go: up one dir, main page]

0% found this document useful (0 votes)
76 views19 pages

C Preprocessor Always A

The document contains a series of multiple choice questions about C preprocessor directives and macros, including questions about how the preprocessor acts before compilation, how macros are defined and used, and common properties of macros. The correct answers are provided for each question along with optional explanations. The questions cover a range of topics relating to macros and preprocessor directives in C programming.

Uploaded by

Swapnil Shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views19 pages

C Preprocessor Always A

The document contains a series of multiple choice questions about C preprocessor directives and macros, including questions about how the preprocessor acts before compilation, how macros are defined and used, and common properties of macros. The correct answers are provided for each question along with optional explanations. The questions cover a range of topics relating to macros and preprocessor directives in C programming.

Uploaded by

Swapnil Shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

((MARKS)) (1/2/3...

) 1

((QUESTION)) C preprocessor always acts before compilation and ...

((OPTION_A)) Takes care of conditional compilation

((OPTION_B)) Takes care of macros

((OPTION_C)) Takes care of include files

((OPTION_D)) All of the above

((CORRECT_CHOICE)) (A/B/C/D) D

((EXPLANATION)) (OPTIONAL) Definition of macro


((MARKS)) (1/2/3...) 1

((QUESTION)) A pre-processor command

((OPTION_A)) need not start on a new line

((OPTION_B)) need not start on the first column

((OPTION_C)) has # as the first character

((OPTION_D)) comes before the first executable statement

((CORRECT_CHOICE)) (A/B/C/D) C

((EXPLANATION)) (OPTIONAL) It is starting with # char.


((MARKS)) (1/2/3...) 1

((QUESTION)) which keyword is used to define the macros in C?

((OPTION_A)) macro

((OPTION_B)) define

((OPTION_C)) #define

((OPTION_D)) none of the mentioned

((CORRECT_CHOICE)) (A/B/C/D) C

((EXPLANATION)) (OPTIONAL) #define pre-processor directive is used for defining macros.


((MARKS)) (1/2/3...) 1

((QUESTION)) What is the other name of the macro?

((OPTION_A)) scripted directive

((OPTION_B)) executed directive

((OPTION_C)) link directive

((OPTION_D)) none of the mentioned

((CORRECT_CHOICE)) (A/B/C/D) A

((EXPLANATION)) (OPTIONAL) Macro are known as scripted directive


((MARKS)) (1/2/3...) 1

((QUESTION)) Choose the correct statement.


I. The scope of a macro definition need not be the entire
program.
II. The scope of a macro definition extends from the point
of definition to the end of the file.
III. New line is a macro definition delimiter.
IV. A macro definition may go beyond a line.

((OPTION_A)) I and II

((OPTION_B)) II and III

((OPTION_C)) I , II, and III

((OPTION_D)) I, II, III and IV

((CORRECT_CHOICE)) (A/B/C/D) D

((EXPLANATION)) (OPTIONAL) All are the properties of macro.


((MARKS)) (1/2/3...) 1

((QUESTION)) Which one of the following is invalid macro in C


programming?

((OPTION_A)) #pragma

((OPTION_B)) #error

((OPTION_C)) #ifndef

((OPTION_D)) #elseif

((CORRECT_CHOICE)) (A/B/C/D) D

((EXPLANATION)) (OPTIONAL) Option A, B, and C are available in latest definition of


ANSI C
((MARKS)) (1/2/3...) 1

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

Guess the output?

((OPTION_A)) 4

((OPTION_B)) 64

((OPTION_C)) 16

((OPTION_D)) None of the above

((CORRECT_CHOICE)) (A/B/C/D) B

((EXPLANATION)) (OPTIONAL) Macro square() is called with value 4


Apply rules of arithmetic operations
((MARKS)) (1/2/3...) 1

((QUESTION)) #include<stdio.h>
#define a 10
void main()
{
#define a 50
printf("%d", a);
}
Guess the output?

((OPTION_A)) 50

((OPTION_B)) 10

((OPTION_C)) Compiler Error

((OPTION_D)) None of the above

((CORRECT_CHOICE)) (A/B/C/D) A

((EXPLANATION)) (OPTIONAL) Value of variable a is replaced with new macro definition


((MARKS)) (1/2/3...) 1

((QUESTION)) #include <stdio.h>


#define prod(a,b) a*b

int main(void) {
// your code goes here
int x=3,y=4;
printf("%d", prod(x+2,y-1));
return 0;
}
Guess the output??

((OPTION_A)) 10

((OPTION_B)) 15

((OPTION_C)) 12

((OPTION_D)) 11

((CORRECT_CHOICE)) (A/B/C/D) A

((EXPLANATION)) (OPTIONAL) Replace the values and compute result.


((MARKS)) (1/2/3...) 1

((QUESTION)) Guess the output?

#include <stdio.h>
#define max 5
int main(void) {
// your code goes here
int i = 0;
i = max++;
printf("%d", i++);
return 0;
}

((OPTION_A)) 5

((OPTION_B)) 6

((OPTION_C)) 7

((OPTION_D)) Error

((CORRECT_CHOICE)) (A/B/C/D) D

((EXPLANATION)) (OPTIONAL) Compile time error:


lvalue required as increment operand
((MARKS)) (1/2/3...) 1

((QUESTION)) Guess the output?

#define x 10 * 10
#include <stdio.h>

int main()
{
int a = x + x;
printf("%d",a);
return 0;
}

((OPTION_A)) 20

((OPTION_B)) 10

((OPTION_C)) 100

((OPTION_D)) 200

((CORRECT_CHOICE)) (A/B/C/D) D

((EXPLANATION)) (OPTIONAL) Replace the cod with macro values.


((MARKS)) (1/2/3...) 1

((QUESTION)) Guess the output?

#define x 10 + 5
#include <stdio.h>

int main()
{
int a = x * x;
printf("%d",a);
return 0;
}

((OPTION_A)) 225

((OPTION_B)) 65

((OPTION_C)) 85

((OPTION_D)) 155

((CORRECT_CHOICE)) (A/B/C/D) B

((EXPLANATION)) (OPTIONAL) Apply rules of arithmetic operations


((MARKS)) (1/2/3...) 1

((QUESTION)) Guess the output?

#include <stdio.h>
#define x 10

int main(void) {
// your code goes here
x = 20;
printf("%d", x);
return 0;
}

((OPTION_A)) 20

((OPTION_B)) 10

((OPTION_C)) 0

((OPTION_D)) Compile error

((CORRECT_CHOICE)) (A/B/C/D) D

((EXPLANATION)) (OPTIONAL) Compile error: error: lvalue required as l


eft
operand of assignment
((MARKS)) (1/2/3...) 1

((QUESTION)) Guess the output?


#include <stdio.h>
#define x 10

int main(void) {
// your code goes here
x++;
printf("%d", x);
return 0;
}

((OPTION_A)) 10

((OPTION_B)) 11

((OPTION_C)) No output will be displayed

((OPTION_D)) Compile error

((CORRECT_CHOICE)) (A/B/C/D) D

((EXPLANATION)) (OPTIONAL) error: lvalue required as increment o


perand
((MARKS)) (1/2/3...) 1

((QUESTION)) Guess the output?

#define x 10
#define x 20
#include <stdio.h>

int main()
{
printf("%d", x);
return 0;
}

((OPTION_A)) 10

((OPTION_B)) 20

((OPTION_C)) 0

((OPTION_D)) Error

((CORRECT_CHOICE)) (A/B/C/D) D

((EXPLANATION)) (OPTIONAL) Most latest assignment will be used for x


((MARKS)) (1/2/3...) 1

((QUESTION)) Guess the output?


#define x 10;
#define x 20;
#include <stdio.h>

int main()
{
printf("%d", x);
return 0;
}

((OPTION_A)) 10

((OPTION_B)) 20

((OPTION_C)) 0

((OPTION_D)) Error

((CORRECT_CHOICE)) (A/B/C/D) D

((EXPLANATION)) (OPTIONAL) Macro definition does not require semicolon at the end
((MARKS)) (1/2/3...) 1

((QUESTION)) Guess the output?

#define x 10

int main()
{
printf("%d %c", x);
return 0;
}

((OPTION_A)) 10 ‘\0’

((OPTION_B)) 10

((OPTION_C)) 10 Garbage value

((OPTION_D)) Error

((CORRECT_CHOICE)) (A/B/C/D) C

((EXPLANATION)) (OPTIONAL) Value of x will be used and for char value garbage will be
displayed
((MARKS)) (1/2/3...) 1

((QUESTION)) #define x 65

int main()
{
printf("%d %c", x, x);
return 0;
}
Guess the output?

((OPTION_A)) 65

((OPTION_B)) 65 65

((OPTION_C)) 65 a

((OPTION_D)) 65 A

((CORRECT_CHOICE)) (A/B/C/D) D

((EXPLANATION)) (OPTIONAL) Value of x is taken from macro.


ASCII 65 is of letter ‘A’
((MARKS)) (1/2/3...) 1

((QUESTION)) Output??
#define x 65

int main()
{
printf("%d", x+5+x/5);
return 0;
}

((OPTION_A)) 27

((OPTION_B)) 79

((OPTION_C)) 83

((OPTION_D)) 0

((CORRECT_CHOICE)) (A/B/C/D) C

((EXPLANATION)) (OPTIONAL) Apply arithmetic operations priority rules.

You might also like