#include<stdio.h>
#define MAN(x, y) ((x)>(y)) ? (x):(y);
int main()
{
int i=10, j=5, k=0;
k = MAN(++i, j++);
printf("%d, %d, %d\n", i, j, k);
return 0;
}
A:
12, 6, 12
B:
11, 5, 11
C:
11, 5, Garbage
D:
12, 6, Garbage
Answer:A
The macro MAN(x, y) ((x)>(y)) ? (x):(y); returns the biggest number of given two numbers.
Step 1: int i=10, j=5, k=0; The variable i, j, k are declared as an integer type and initialized to value 10, 5, 0 respectively.
Step 2: k = MAN(++i, j++); becomes,
=> k = ((++i)>(j++)) ? (++i):(j++);
=> k = ((11)>(5)) ? (12):(6);
=> k = 12
Step 3: printf("%d, %d, %d\n", i, j, k); It prints the variable i, j, k.
In the above macro step 2 the variable i value is increemented by 2 and variable j value is increemented by 1.
Hence the output of the program is 12, 6, 12
Discuss About this Question.
In which stage the following code #include<stdio.h> gets replaced by the contents of the file stdio.h
A:
During editing
B:
During linking
C:
During execution
D:
During preprocessing
Answer:D
The preprocessor replaces the line #include <stdio.h> with the system header file of that name. More precisely, the entire text of the file 'stdio.h' replaces the #include directive.
Discuss About this Question.
What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?
#include<stdio.h>
#define SWAP(a, b, c)(c t; t=a, a=b, b=t)
int main()
{
int x=10, y=20;
SWAP(x, y, int);
printf("%d %d\n", x, y);
return 0;
}
A:
It compiles
B:
Compiles with an warning
C:
Not compile
D:
Compiles and print nothing
Answer:C
The code won't compile since declaration of t cannot occur within parenthesis.
Discuss About this Question.
Ad Slot (Above Pagination)
Install ExamAdept
Fast access — add this app to your device.
To install on iPhone/iPad: tap Share → Add to Home Screen.
Discuss About this Question.