Programming and data structure miscellaneous
- The attributes of three arithmetic operators in some programming language are given below.
Operator Precedence Associativity Parity + High Left Binary – Medium Right Binary * Low Left Binary
The value of the expression 2 – 5 + 1 – 7 * 3 in this language is _________.
-
View Hint View Answer Discuss in Forum
2 – 5 + 1 – 7 * 3 ⇒ 2 – (5 + 1) – 7 * 3
⇒ 2 – 6 – 7 * 3 ⇒ 2 – (6 – 7) * 3 ⇒ 2 – (–1) * 3
⇒ (2 + 1) * 3 ⇒ 3 * 3 = 9Correct Option: B
2 – 5 + 1 – 7 * 3 ⇒ 2 – (5 + 1) – 7 * 3
⇒ 2 – 6 – 7 * 3 ⇒ 2 – (6 – 7) * 3 ⇒ 2 – (–1) * 3
⇒ (2 + 1) * 3 ⇒ 3 * 3 = 9
- The value printed by the following program is _______.
void f(int* p, int m){
m = m + 5;
*p = *p+m;
return;
}
void main () {
int i=5, j=10;
f(& i, j);
printf (“%d”, i+j);
}
-
View Hint View Answer Discuss in Forum
The address of i and value of j are passed to the function of f. f modifies i’s value to 20. j’s value remains same (as its value is passed not the reference). The value printed by the program will be i + j = 20 + 10 = 30.
Correct Option: D
The address of i and value of j are passed to the function of f. f modifies i’s value to 20. j’s value remains same (as its value is passed not the reference). The value printed by the program will be i + j = 20 + 10 = 30.
- A variable x is said to be live at a statement Si in a program if the following three conditions hold simultaneously:
I. There exists a statement Sj that uses x
II. There is a path from Si to Sj in the flow graph corresponding to the program
III. The path has no intervening assignment to x including at Si and Sj
The variables which are live at the statement in basic block 2 and at the statement in basic block 3 of the above control flow graph are
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
NA
- What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes of memory ?
int main()
{
unsigened int x[4] [3] = {(1,2,3), {4,5,6}, {7, 8, 9}, {10, 11, 12}};
printf(“%u, %u, %u”, x+3, *(x+3),
*(x+2)+3);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
NA
- Consider the following pseudo code, where x and y are positive integers.
begin
q: = 0
r: = x
while r > y do
being
r: = r – y
q: = q + 1
end
end
The post condition that needs to be satisfied after the program terminates is
-
View Hint View Answer Discuss in Forum
The loop terminater when r < y. so, r < y is one post condition.
In each iteration q is incremented by 1 and y is subtracted from r. Initialvalue of r is x.So, loop iterates x times and q will be equal to x y y
and r = x% y ⇒ x = qy + r
So, (b) is correct answer.
Correct Option: B
The loop terminater when r < y. so, r < y is one post condition.
In each iteration q is incremented by 1 and y is subtracted from r. Initialvalue of r is x.So, loop iterates x times and q will be equal to x y y
and r = x% y ⇒ x = qy + r
So, (b) is correct answer.