# ISRO2014-32

4k views

What is the output of the following C program?

#include<stdio.h>
void main(void){
int shifty;
shifty=0570;
shifty=shifty>>4;
shifty=shifty<<6;
printf("The value  of shifty is %o \n",shifty);
}
1. The value of shifty is 15c0
2. The value of shifty is 4300
3. The value of shifty is 5700
4. The value of shifty is 2700

Ans is D) 2700

If an integer constant starts with 0, it is considered an octal constant. So 0570 = 101 111 000 in binary as each octal digit can be directly converted to 3 bits. Now, >>4 (right shift 4) gives 010 111 and <<6 (left shift 6) gives 010 111 000 000 = 2700 in octal. If we use "%d" in printf, this would be 1024+64*7 = 1472.

selected by
0
pls explain
0
see 0570 mean its in octal .

so 000 101 111 000

now >>4 means 010 111

now <<6 means 010 111 000 000 = 2700 . peace
2
what is the meaning of PEACE,please tell me just for the sake of knowledge .every time after explaination you use this word.
6

I use this but not every time .

peace means in hindi "Shanti" , so im looking for her :D :P

anyway its like this  ✌ .

0
can u plz explain properly..how do u split those binary  >>4 010 111
1

How  this would be 1024+64*7 = 1472 If we use "%d" in printf. octal to decimal for 2700 is not 1472. how u r getting this??

0
2*8^3 + 7*8^2 =1472
1 vote

It is in octal(0570)8 Since it starts with octal, so take 3 bits in binary format.

(0570)8=000 101 111 000

shifty>>4(left shift the bits 4 times)=100 000 010 111

shifty<<6(right shift the bits 6 times)=010 111 000 000=(2700)8

0
kk method is correct ...but i don't know how perform left sift or right shift..
0
ITS not shift by 4 times its by shift by 4 bits and is right shift and 2nd one is left shift by 6 bits.
0

It is in octal(0570)8 Since it starts with octal, so take 3 bits in binary format.

(0570)8=000 101 111 000

shifty>>4(left shift the bits 4 times)=100 000 010 111

shifty<<6(right shift the bits 6 times)=010 111 000 000

how did you that ?

i think it should be

shifty>>4(left shift the bits 4 times)=100 000 010 111

shifty<<6(right shift the bits 6 times)=010 111 000 100

There is an error in program....for any result main' must return 'int'....
D) 2700
0
give a solution
5

shifty = 0570  ( decimal equivalent = (376)10 = (570)8 )

shifty = shifty >>4 = ( 376/(24) ) = 23

shifty = shifty <<6 = 23 * 26 = 1472

(1472)10 = ( 2700)8

0
0
what does > > or < <  means in C language..?
0
>>is right shift and << is left shift operator
0
right shift of  110001011 ..??
int shifty;
shifty=0570;

If an integer constant begins with 0x or 0X, it is hexadecimal. If it begins with the digit 0, it is octal. Otherwise, it is assumed to be decimal.

shifty=shifty>>4;

>> means Right Shift means "divide by 2"

shifty=shifty<<6;

<< means Left Shift means "multiply by 2"

Option D

## Related questions

1 vote
1
2.5k views
The following three 'C' language statements is equivalent to which single statement? y=y+1; z=x+y; x=x+1 z = x + y + 2; z = (x++) + (++y); z = (x++) + (y++); z = (x++) + (++y) + 1;