2 Replies - 241 Views - Last Post: 07 February 2013 - 07:07 PM Rate Topic: -----

#1 laylasareini  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-February 13

fragment code question

Posted 07 February 2013 - 06:02 PM

this fragment was on a past exam;

Consider the following code fragment:
int x=2, y=4; char ch;
cin >> x; cin.get(ch); cin >> y;
cout << x * y;
7)
If the user types the following at standard input, what does the above code fragment print? Note: <Enter> means they pressed the “Enter” key
2 * 2 <Enter>

A)4
B)5 C)6 D)8 E)10

The answer is 10 but i don't understand how

Is This A Good Question/Topic? 0
  • +

Replies To: fragment code question

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3075
  • Posts: 10,783
  • Joined: 08-August 08

Re: fragment code question

Posted 07 February 2013 - 06:43 PM

When I run that code I get 0 if I include the spaces: 2<space>*<space>2<enter>
If I don't, I get 4: 2*2<enter>
Was This Post Helpful? 0
  • +
  • -

#3 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1396
  • View blog
  • Posts: 4,872
  • Joined: 19-February 09

Re: fragment code question

Posted 07 February 2013 - 07:07 PM

When I run that code I get 33554436 if I include the spaces.
If I don't, I get 4.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1