Work it out

C

cogno_byte

I was given a 'C' code to dry run and get the output.
Plz help me out with the output.

Int a=15,b=10;
b<<=a;

wht value would it yield?And plz if posible state the reason.
 
J

Jordan Abel

I was given a 'C' code to dry run and get the output.
Plz help me out with the output.

Int a=15,b=10;

You misspelled "int".
b<<=a;

wht value would it yield?And plz if posible state the reason.

On a 16-bit system, this is undefined behavior because it causes integer
overflow. A plausible value on a 16-bit system might be 0. If int is at
least 19 bits, the result will be 0x50000, or 327680.
 
P

pemo

cogno_byte said:
I was given a 'C' code to dry run and get the output.
Plz help me out with the output.

Int a=15,b=10;
b<<=a;

wht value would it yield?And plz if posible state the reason.

Why don't you try it?

int a=15,b=10;

printf("%d\n", b<<=a);

b <<= a

means

b = b << a

b's value is set to b's value left-shifted a bits.
 
I

Ico

Jordan Abel said:
You misspelled "int".

He also misspelled 'please'
and here he does it again, now with the word 'what'

Cogno_byte, if you want people to take a serious look at your questions,
a good start would be to state them in proper english. Nobody expects
you to use perfect language, but all those intentional abbreviations
make your message only harder to read.
 
C

CBFalconer

pemo said:
Why don't you try it?

int a=15,b=10;
printf("%d\n", b<<=a);

b <<= a

means

b = b << a

b's value is set to b's value left-shifted a bits.

==============
*Not a pedant*
==============

Your snippet will not compile, and even if you add the appropriate
things the left shift operation on an integer is very likely to
cause overflow and undefined behaviour. This is very useful when
demonstrating your nifty software to the VP for marketing, or a
prospective funder for the company, etc.

Such sloppy coding deserves an ignominous burial. Up the pedants.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,802
Messages
2,569,662
Members
45,433
Latest member
andrewartemow

Latest Threads

Top