473,396 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Work it out

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.

Jan 26 '06 #1
5 1364
On 2006-01-26, cogno_byte <b.************@gmail.com> wrote:
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.
Jan 26 '06 #2
cogno_byte wrote:
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.

--
==============
*Not a pedant*
==============
Jan 26 '06 #3
"cogno_byte" <b.************@gmail.com> writes:
I was given a 'C' code to dry run and get the output.

[...]

So why didn't you?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 26 '06 #4
Ico
Jordan Abel <ra*******@gmail.com> wrote:
On 2006-01-26, cogno_byte <b.************@gmail.com> wrote:
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".


He also misspelled 'please'
b<<=a;

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


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.
--
:wq
^X^Cy^K^X^C^C^C^C
Jan 26 '06 #5
pemo wrote:
cogno_byte wrote:
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.

==============
*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/>
Jan 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jonas | last post by:
This works fine in Win XP but does not work at all in Win 98. Private WithEvents objIExplorer As InternetExplorer I have to do it like this to get it to work in Win 98 Dim objIExplorer As...
3
by: Douglas Buchanan | last post by:
Buttons don't work if form is opened on startup A2k If 'frmMain' is set to open by default at startup none of the buttons work. If 'frmMain' is opened from the database window then all the...
15
by: Brett | last post by:
I'd like to know what management and the work environment are like where you work. I need something relative to compare my current work environment. Here's a few questions I have: 1.) Is it...
2
by: Holysmoke | last post by:
Hi, I have a asp.net form with a button in it. In the onlclick event of button I want to write a function which does some a bit of work with a timespan of 15 seconds. So I want to show a image...
1
by: Jeff | last post by:
Hello, I have developed a library of controls but for the life of me cannot get ToolboxBitmapAttribute to work -- my image simply will not display in the toolbox of any project using my...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
33
by: bonk | last post by:
I have an application that needs to perform some background work, i.e. Logging, wich must not block the main thread. How would I basically design such a scenario? It is obvious that I should do...
11
Niheel
by: Niheel | last post by:
http://bytes.com/images/howtos/information_overloaded.jpgPaul Graham wrote an interesting article a few months back about how the internet is leading to information overload for information workers...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.