Académique Documents
Professionnel Documents
Culture Documents
Questions
L1.Q1 : Write the output of the following program
#defineABC 20
#define XYZ 10
#define XXX ABC - XYZ
void main()
{
int a;
a = XXX * 10;
printf("%d ", a);
}
Answers
L1.A1
Solution for L1.Q1
a = xxx * 10
which is => a = ABC - XYZ * 10
=> a = 20 - 10 * 10
=> a = 20 - 100
=> a = -80
L1.A2
Solution for L1.Q2
Actual substitution is like this :
a /= cnt; /* ie. a /= 0 */
which leads to divide-by-zero error.
L1.A4
Solution for L1.Q4
the result will be c = 40 and abc = 0;
because the scope of the variable 'abc' inside if(c) {.. }
is not valid out side that if (.) { .. }.
L1.A5
Solution for L1.Q5
The answer is 7. The first condition ++k < 5 is checked and
it is false (Now k = 6). So, it checks the 3rd condition
(or condition ++k <= 8) and (now k = 7) it is true. At this
point k value is incremented by twice, hence the value of k
becomes 7.
L1.A6
Solution for L1.Q6
The solution depends on the implementation of stack.
(Depends on OS) In some machines the arguments are passed
from left to right to the stack. In this case the result
will be
Main : 5 7 Fn : 7 7