search
Log In
5 votes
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
in Programming 4k views

5 Answers

12 votes
 
Best answer
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 i`m looking for her :D :P

anyway it`s 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

So answer is D

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

0 votes
There is an error in program....for any result main' must return 'int'....
0 votes
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
kk answer is given octat
0
what does > > or < <  means in C language..?
0
>>is right shift and << is left shift operator
0
right shift of  110001011 ..??
0 votes
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.

(https://docs.microsoft.com/en-us/cpp/c-language/c-integer-constants)


shifty=shifty>>4;
 
>> means Right Shift means "divide by 2"

 shifty=shifty<<6;
 
<< means Left Shift means "multiply by 2"
 
Option D
Answer:

Related questions

1 vote
4 answers
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;
asked Jun 25, 2016 in Programming jenny101 2.5k views
7 votes
7 answers
2
3.2k views
What is the output of the following C program? #include<stdio.h> #define SQR(x) (x*x) int main() { int a; int b=4; a=SQR(b+2); printf("%d\n",a); return 0; } 14 36 18 20
asked Jun 22, 2016 in Programming pooja14 3.2k views
5 votes
2 answers
3
2.8k views
How many lines of output does the following C code produce? #include<stdio.h> float i=2.0; float j=1.0; float sum = 0.0; main() { while (i/j > 0.001) { j+=j; sum=sum+(i/j); printf("%f\n", sum); } } 8 9 10 11
asked Jun 22, 2016 in Programming Sourabh Kumar 2.8k views
3 votes
2 answers
4
3.1k views
Which of the following is true with respect to Reference? A reference can never be NULL A reference needs an explicit dereferencing mechanism A reference can be reassigned after it is established A reference and pointer are synonymous
asked Sep 23, 2015 in Programming ajit 3.1k views
...