26.
What will be the output of the program?
#include<stdio.h>
#define HELLO junk
int main()
{
printf(“HELLO\n”);
return 0;
}
A. junk
B. HELLO
C. Error
D. Nothing will print
Answer: Option B
Explanation:
printf(“HELLO\n”); It prints the text “HELLO”. There is no macro calling inside the printf statement occured.
27.
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;
}
A. 2, 3, 4,
B. 2, 2, 2,
C. 3, 3, 3,
D. 4, 4, 4,
Answer: Option A
Explanation:
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.
28.
What will be the output of the program?
#include<stdio.h>
#define MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c)
int main()
{
int x;
x = MAX(3+2, 2+7, 3+7);
printf(“%d\n”, x);
return 0;
}
A. 5
B. 9
C. 10
D. 3+7
Answer: Option C
Explanation:
The macro MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c) returns the biggest of given three numbers.
Step 1: int x; The variable x is declared as an integer type.
Step 2: x = MAX(3+2, 2+7, 3+7); becomes,
=> x = (3+2 >2+7 ? 3+2 > 3+7 ? 3+2 : 3+7: 2+7 > 3+7 ? 2+7 : 3+7)
=> x = (5 >9 ? (5 > 10 ? 5 : 10): (9 > 10 ? 9 : 10) )
=> x = (5 >9 ? (10): (10) )
=> x = 10
Step 3: printf(“%d\n”, x); It prints the value of ‘x’.
Hence the output of the program is “10”.
29.
Point out the error in the program
#include<stdio.h>
#define SI(p, n, r) float si; si=p*n*r/100;
int main()
{
float p=2500, r=3.5;
int n=3;
SI(p, n, r);
SI(1500, 2, 2.5);
return 0;
}
A. 26250.00 7500.00
B. Nothing will print
C. Error: Multiple declaration of si
D. Garbage values
Answer: Option C
Explanation:
The macro #define SI(p, n, r) float si; si=p*n*r/100; contains the error. To remove this error, we have to modify this macro to
#define SI(p,n,r) p*n*r/100
30.
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;
}
A. Error: unexpected end of file because there is no matching #endif
B. The number is odd
C. Garbage values
D. None of above
Answer: Option A
Explanation:
The conditional macro #if must have an #endif. In this program there is no #endif statement written.