You are here : Home >> Infosys Archive >> Infosys Pseudo Codes Questions
Q. Find the output of following pseudo code :
int main()
{
int x =4, y = 0;
int z;
z = (y++, y);
printf(“%dn”, z);
return 0;
}
A. 1
B. 0
C. Undefined Behavior due to order of evaluation can be different.
D. Compilation Error
(a)
Explanation : Consider the line : z = (y++, y)
So, at first z is assigned with y++ after this statement y is incremented to 1. Next expression is z = y, so z = 1.
You are here : Home >> Infosys Archive >> Infosys Pseudo Codes Questions
Q. Find the output of following pseudo code :
Set j=1, k=1
for each i from 1 to 5 :
print(k)
j+=1
k+=j
end-for
a. 1 2 3 4 5
b. 4 6 8 10
c. 1 1 2 3 5
d. 1 3 6 10 15
(d)
Explanation : Simply follow the looping statements, where in each iteration k is printed and then j is incremented by 1 and k is incremented by j.
I LOVE COG, JUST AWESOME CONTENT.
I think its ans is – C1 and C2 and NOT c4
correct ans is b
what they are provided as a answer of this question 18 as d is wrong answer…….
Correct answer is c
here 16. option b is the answer