Java C Preprocessor Quiz 2 | Java Question and Answers
Finish Quiz
0 of 20 questions completed
Questions:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
Information
Lets take free Java C Preprocessor Quiz 2 | Java Question and Answers. Free Java C Preprocessor Quiz, Online Java, online Test Quiz 2. Java C Preprocessor Quiz 2 Question and Answers 2024. Java online Test Quiz 2. Java C Preprocessor Quiz 2 Free Mock Test 2024. Java C Preprocessor Quiz 2 Question and Answers in PDF. The Java online mock test paper is free for all students. Spring Online is very useful for exam preparation and getting for Rank. Java C Preprocessor Quiz 2 Question and Answers in English. Java C Preprocessor Mock test for topic via C Preprocessor Mode. Here we are providing Java C Preprocessor Quiz in English Now Test your self for “C Preprocessor Online Quiz in English” Exam by using below quiz…
This paper has 20 questions.
Time allowed is 25 minutes.
The Java C Preprocessor Mock Test is Very helpful for all students. Now Scroll down below n click on “Start Quiz” or “Start Test” and Test yourself.
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading...
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
Results
0 of 20 questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 points, (0)
Average score |
|
Your score |
|
Categories
- Not categorized 0%
Pos. | Name | Entered on | Points | Result |
---|---|---|---|---|
Table is loading | ||||
No data available | ||||
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- Answered
- Review
-
Question 1 of 20
1. Question
Will the program compile successfully?
#include<stdio.h>
int main()
{
#ifdef NOTE
int a;
a=10;
#else
int a;
a=20;
#endif
printf(“%d “, a);
return 0;
}Correct
Yes, this program will compile and run successfully and prints 20.
The macro #ifdef NOTE evaluates the given expression to 1. If satisfied it executes the #ifdef block statements. Here #ifdef condition fails because the Macro NOTE is nowhere declared.
Hence the #else block gets executed, the variable a is declared and assigned a value of 20.
printf(“%d “, a); It prints the value of variable a 20.
Incorrect
Yes, this program will compile and run successfully and prints 20.
The macro #ifdef NOTE evaluates the given expression to 1. If satisfied it executes the #ifdef block statements. Here #ifdef condition fails because the Macro NOTE is nowhere declared.
Hence the #else block gets executed, the variable a is declared and assigned a value of 20.
printf(“%d “, a); It prints the value of variable a 20.
-
Question 2 of 20
2. Question
Would the following typedef work?
typedef #include l;Correct
Because typedef goes to work after preprocessing.
Incorrect
Because typedef goes to work after preprocessing.
-
Question 3 of 20
3. Question
Will it result in to an error if a header file is included twice?
Correct
Unless the header file has taken care to ensure that if already included it does not get included again.
Turbo C, GCC compilers would take care of these problems, generate no error.
Incorrect
Unless the header file has taken care to ensure that if already included it does not get included again.
Turbo C, GCC compilers would take care of these problems, generate no error.
-
Question 4 of 20
4. Question
In a macro call the control is passed to the macro.
Correct
False, Always the macro is substituted by the given text/expression.
Incorrect
False, Always the macro is substituted by the given text/expression.
-
Question 5 of 20
5. Question
The preprocessor can trap simple errors like missing declarations, nested comments or mismatch of braces.
Correct
False, the preprocessor cannot trap the errors, it only replaces the macro with the given expression. But the compiler will detect errors.
Incorrect
False, the preprocessor cannot trap the errors, it only replaces the macro with the given expression. But the compiler will detect errors.
-
Question 6 of 20
6. Question
What will be the output of the program?
#include<stdio.h>
#define MAX(a, b) (a > b ? a : b)int main()
{
int x;
x = MAX(3+2, 2+7);
printf(“%d “, x);
return 0;
}Correct
The macro MAX(a, b) (a > b ? a : b) returns the biggest value of the given two numbers.
Step 1 : int x; The variable x is declared as an integer type.
Step 2 : x = MAX(3+2, 2+7); becomes,
=> x = (3+2 > 2+7 ? 3+2 : 2+7)
=> x = (5 > 9 ? 5 : 9)
=> x = 9
Step 3 : printf(“%d “, x); It prints the value of variable x.
Hence the output of the program is 9.Incorrect
The macro MAX(a, b) (a > b ? a : b) returns the biggest value of the given two numbers.
Step 1 : int x; The variable x is declared as an integer type.
Step 2 : x = MAX(3+2, 2+7); becomes,
=> x = (3+2 > 2+7 ? 3+2 : 2+7)
=> x = (5 > 9 ? 5 : 9)
=> x = 9
Step 3 : printf(“%d “, x); It prints the value of variable x.
Hence the output of the program is 9. -
Question 7 of 20
7. Question
What will be the output of the program?
#include<stdio.h>
#define MESS junkint main()
{
printf(“MESS “);
return 0;
}Correct
printf(“MESS “); It prints the text “MESS”. There is no macro calling inside the printf statement occured.
Incorrect
printf(“MESS “); It prints the text “MESS”. There is no macro calling inside the printf statement occured.
-
Question 8 of 20
8. Question
What will be the output of the program?
#include<stdio.h>
#define SQUARE(x) x*xint main()
{
float s=10, u=30, t=2, a;
a = 2*(s-u*t)/SQUARE(t);
printf(“Result = %f”, a);
return 0;
}Correct
The macro function SQUARE(x) x*x calculate the square of the given number x. (Eg: 102)
Step 1: float s=10, u=30, t=2, a; Here the variable s, u, t, a are declared as an floating point type and the variable s, u, t are initialized to 10, 30, 2.
Step 2: a = 2*(s-u*t)/SQUARE(t); becomes,
=> a = 2 * (10 – 30 * 2) / t * t; Here SQUARE(t) is replaced by macro to t*t .
=> a = 2 * (10 – 30 * 2) / 2 * 2;
=> a = 2 * (10 – 60) / 2 * 2;
=> a = 2 * (-50) / 2 * 2 ;
=> a = 2 * (-25) * 2 ;
=> a = (-50) * 2 ;
=> a = -100;
Step 3: printf(“Result=%f”, a); It prints the value of variable a.
Hence the output of the program is -100Incorrect
The macro function SQUARE(x) x*x calculate the square of the given number x. (Eg: 102)
Step 1: float s=10, u=30, t=2, a; Here the variable s, u, t, a are declared as an floating point type and the variable s, u, t are initialized to 10, 30, 2.
Step 2: a = 2*(s-u*t)/SQUARE(t); becomes,
=> a = 2 * (10 – 30 * 2) / t * t; Here SQUARE(t) is replaced by macro to t*t .
=> a = 2 * (10 – 30 * 2) / 2 * 2;
=> a = 2 * (10 – 60) / 2 * 2;
=> a = 2 * (-50) / 2 * 2 ;
=> a = 2 * (-25) * 2 ;
=> a = (-50) * 2 ;
=> a = -100;
Step 3: printf(“Result=%f”, a); It prints the value of variable a.
Hence the output of the program is -100 -
Question 9 of 20
9. Question
What will be the output of the program?
#include<stdio.h>
#define PRINT(int) printf(“int=%d, “, int);int main()
{
int x=2, y=3, z=4;
PRINT(x);
PRINT(y);
PRINT(z);
return 0;
}Correct
The macro PRINT(int) print(“%d,”, int); prints the given variable value in an integer format.
Step 1: int x=2, y=3, z=4; The variable x, y, z are declared as an integer type and initialized to 2, 3, 4 respectively.
Step 2: PRINT(x); becomes printf(“int=%d,”,x). Hence it prints int=2.
Step 3: PRINT(y); becomes printf(“int=%d,”,y). Hence it prints int=3.
Step 4: PRINT(z); becomes printf(“int=%d,”,z). Hence it prints int=4.
Hence the output of the program is int=2, int=3, int=4.Incorrect
The macro PRINT(int) print(“%d,”, int); prints the given variable value in an integer format.
Step 1: int x=2, y=3, z=4; The variable x, y, z are declared as an integer type and initialized to 2, 3, 4 respectively.
Step 2: PRINT(x); becomes printf(“int=%d,”,x). Hence it prints int=2.
Step 3: PRINT(y); becomes printf(“int=%d,”,y). Hence it prints int=3.
Step 4: PRINT(z); becomes printf(“int=%d,”,z). Hence it prints int=4.
Hence the output of the program is int=2, int=3, int=4. -
Question 10 of 20
10. Question
What will be the output of the program?
#include<stdio.h>
#define CUBE(x) (x*x*x)int main()
{
int a, b=3;
a = CUBE(b++);
printf(“%d, %d “, a, b);
return 0;
}Correct
The macro function CUBE(x) (x*x*x) calculates the cubic value of given number
Step 1: int a, b=3; The variable a and b are declared as an integer type and varaible b id initialized to 3.
Step 2: a = CUBE(b++); becomes
=> a = b++ * b++ * b++;
=> a = 3 * 3 * 3; Here we are using post-increement operator, so the 3 is not incremented in this statement.
=> a = 27; Here, 27 is store in the variable a. By the way, the value of variable b is incremented by 3. (ie: b=6)
Step 3: printf(“%d, %d “, a, b); It prints the value of variable a and b.
Hence the output of the program is 27, 6.Incorrect
The macro function CUBE(x) (x*x*x) calculates the cubic value of given number
Step 1: int a, b=3; The variable a and b are declared as an integer type and varaible b id initialized to 3.
Step 2: a = CUBE(b++); becomes
=> a = b++ * b++ * b++;
=> a = 3 * 3 * 3; Here we are using post-increement operator, so the 3 is not incremented in this statement.
=> a = 27; Here, 27 is store in the variable a. By the way, the value of variable b is incremented by 3. (ie: b=6)
Step 3: printf(“%d, %d “, a, b); It prints the value of variable a and b.
Hence the output of the program is 27, 6. -
Question 11 of 20
11. Question
What will be the output of the program?
#include<stdio.h>
#define FUN(i, j) i##jint main()
{
int va1=10;
int va12=20;
printf(“%d “, FUN(va1, 2));
return 0;
}Correct
The following program will make you understand about ## (macro concatenation) operator clearly.
#include<stdio.h>
#define FUN(i, j) i##jint main()
{
int First = 10;
int Second = 20;char FirstSecond[] = “JavaTpoint”;
printf(“%s “, Fun(First, Second) );
return 0;
}Output:
——-
JavaTpointIncorrect
The following program will make you understand about ## (macro concatenation) operator clearly.
#include<stdio.h>
#define FUN(i, j) i##jint main()
{
int First = 10;
int Second = 20;char FirstSecond[] = “JavaTpoint”;
printf(“%s “, Fun(First, Second) );
return 0;
}Output:
——-
JavaTpoint -
Question 12 of 20
12. Question
What will be the output of the program?
#include<stdio.h>
#define SQR(x)(x*x)int main()
{
int a, b=3;
a = SQR(b+2);
printf(“%d “, a);
return 0;
}Correct
The macro function SQR(x)(x*x) calculate the square of the given number x.
Step 1: int a, b=3; Here the variable a, b are declared as an integer type and the variable b is initialized to 3.
Step 2: a = SQR(b+2); becomes,
=> a = b+2 * b+2; Here SQR(x) is replaced by macro to x*x .
=> a = 3+2 * 3+2;
=> a = 3 + 6 + 2;
=> a = 11;
Step 3: printf(“%d “, a); It prints the value of variable a.
Hence the output of the program is 11Incorrect
The macro function SQR(x)(x*x) calculate the square of the given number x.
Step 1: int a, b=3; Here the variable a, b are declared as an integer type and the variable b is initialized to 3.
Step 2: a = SQR(b+2); becomes,
=> a = b+2 * b+2; Here SQR(x) is replaced by macro to x*x .
=> a = 3+2 * 3+2;
=> a = 3 + 6 + 2;
=> a = 11;
Step 3: printf(“%d “, a); It prints the value of variable a.
Hence the output of the program is 11 -
Question 13 of 20
13. Question
What will be the output of the program?
#include<stdio.h>
#define MIN(x, y) (x<y)? x : y;
int main()
{
int x=3, y=4, z;
z = MIN(x+y/2, y-1);
if(z > 0)
printf(“%d “, z);
return 0;
}Correct
The macro MIN(x, y) (x<y)? x : y; returns the smallest value from the given two numbers.
Step 1: int x=3, y=4, z; The variable x, y, z are declared as an integer type and the variable x, y are initialized to value 3, 4 respectively.
Step 2: z = MIN(x+y/2, y-1); becomes,
=> z = (x+y/2 < y-1)? x+y/2 : y – 1;
=> z = (3+4/2 < 4-1)? 3+4/2 : 4 – 1;
=> z = (3+2 < 4-1)? 3+2 : 4 – 1;
=> z = (5 < 3)? 5 : 3;
The macro return the number 3 and it is stored in the variable z.
Step 3: if(z > 0) becomes if(3 > 0) here the if condition is satisfied. It executes the if block statements.
Step 4: printf(“%d “, z);. It prints the value of variable z.
Hence the output of the program is 3Incorrect
The macro MIN(x, y) (x<y)? x : y; returns the smallest value from the given two numbers.
Step 1: int x=3, y=4, z; The variable x, y, z are declared as an integer type and the variable x, y are initialized to value 3, 4 respectively.
Step 2: z = MIN(x+y/2, y-1); becomes,
=> z = (x+y/2 < y-1)? x+y/2 : y – 1;
=> z = (3+4/2 < 4-1)? 3+4/2 : 4 – 1;
=> z = (3+2 < 4-1)? 3+2 : 4 – 1;
=> z = (5 < 3)? 5 : 3;
The macro return the number 3 and it is stored in the variable z.
Step 3: if(z > 0) becomes if(3 > 0) here the if condition is satisfied. It executes the if block statements.
Step 4: printf(“%d “, z);. It prints the value of variable z.
Hence the output of the program is 3 -
Question 14 of 20
14. Question
What will be the output of the program?
#include<stdio.h>
#define SWAP(a, b) int t; t=a, a=b, b=t;
int main()
{
int a=10, b=12;
SWAP(a, b);
printf(“a = %d, b = %d “, a, b);
return 0;
}Correct
The macro SWAP(a, b) int t; t=a, a=b, b=t; swaps the value of the given two variable.
Step 1: int a=10, b=12; The variable a and b are declared as an integer type and initialized to 10, 12 respectively.
Step 2: SWAP(a, b);. Here the macro is substituted and it swaps the value to variable a and b.
Hence the output of the program is 12, 10.Incorrect
The macro SWAP(a, b) int t; t=a, a=b, b=t; swaps the value of the given two variable.
Step 1: int a=10, b=12; The variable a and b are declared as an integer type and initialized to 10, 12 respectively.
Step 2: SWAP(a, b);. Here the macro is substituted and it swaps the value to variable a and b.
Hence the output of the program is 12, 10. -
Question 15 of 20
15. Question
What will be the output of the program?
#include<stdio.h>
#define JOIN(s1, s2) printf(“%s=%s %s=%s “, #s1, s1, #s2, s2);
int main()
{
char *str1=”Java”;
char *str2=”Tpoint”;
JOIN(str1, str2);
return 0;
}Correct
Incorrect
-
Question 16 of 20
16. Question
Preprocessor directive #undef can be used only on a macro that has been #define earlier
Correct
True, #undef can be used only on a macro that has been #define earlier
Example: #define PI 3.14
We can undefine PI macro by #undef PIIncorrect
True, #undef can be used only on a macro that has been #define earlier
Example: #define PI 3.14
We can undefine PI macro by #undef PI -
Question 17 of 20
17. Question
Which of the following are correct preprocessor directives in C?
1: #ifdef
2: #if
3: #elif
4: #undefCorrect
The macros #ifdef #if #elif are called conditional macros.
The macro #undef undefine the previosly declared macro symbol.
Hence all the given statements are macro preprocessor directives.Incorrect
The macros #ifdef #if #elif are called conditional macros.
The macro #undef undefine the previosly declared macro symbol.
Hence all the given statements are macro preprocessor directives. -
Question 18 of 20
18. Question
Point out the error in the program
#include<stdio.h>
int main()
{
int i;
#if A
printf(“Enter any number:”);
scanf(“%d”, &i);
#elif B
printf(“The number is odd”);
return 0;
}Correct
The conditional macro #if must have an #endif. In this program there is no #endif statement written.
Incorrect
The conditional macro #if must have an #endif. In this program there is no #endif statement written.
-
Question 19 of 20
19. Question
Which of the following are correctly formed #define statements in C?
Correct
Incorrect
-
Question 20 of 20
20. Question
What will be the output of the program?
#include<stdio.h>
#define PRINT(i) printf(“%d,”,i)int main()
{
int x=2, y=3, z=4;
PRINT(x);
PRINT(y);
PRINT(z);
return 0;
}Correct
The macro PRINT(i) print(“%d,”, i); prints the given variable value in an integer format.
Step 1: int x=2, y=3, z=4; The variable x, y, z are declared as an integer type and initialized to 2, 3, 4 respectively.
Step 2: PRINT(x); becomes printf(“%d,”,x). Hence it prints 2.
Step 3: PRINT(y); becomes printf(“%d,”,y). Hence it prints 3.
Step 4: PRINT(z); becomes printf(“%d,”,z). Hence it prints 4.
Hence the output of the program is 2, 3, 4.Incorrect
The macro PRINT(i) print(“%d,”, i); prints the given variable value in an integer format.
Step 1: int x=2, y=3, z=4; The variable x, y, z are declared as an integer type and initialized to 2, 3, 4 respectively.
Step 2: PRINT(x); becomes printf(“%d,”,x). Hence it prints 2.
Step 3: PRINT(y); becomes printf(“%d,”,y). Hence it prints 3.
Step 4: PRINT(z); becomes printf(“%d,”,z). Hence it prints 4.
Hence the output of the program is 2, 3, 4.