You are here : Home >> Infosys Archive >> Infosys Pseudo Codes Questions
Q. Find the output of following pseudo code :
int main()
{
int num = 8;
printf (“%d %d”, num << 1, num >> 1);
return 0;
}
A. 8 0
B. 0 0
C. 16 4
D. Error : Can’t Perform operation
(c)
Explanation : ‘<<‘ This is the left shift operator. It takes two numbers, left shifts the bits of the first operand, the second operand decides the number of places to shift. ‘>>’ This is the right shift operator.
8 in binary form : 00001000
Performing Left Shift (<<) : 00010000 => 16
Performing Right Shift (>>) : 00000100 => 4
You are here : Home >> Infosys Archive >> Infosys Pseudo Codes Questions
Q. Find the output of following pseudo code :
int main()
{
int x = 2;
(x & 1) ? printf(“true”) : printf(“false”);
return 0;
}
A. true
B. false
C. 0
D. Error
(b)
Explanation : Above code is easy if you know the working of ternary operators. 2 & 1 is 0, so “false” is the answer.
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