# Questions I got wrong on my final.

Page 1 of 1

## 10 Replies - 836 Views - Last Post: 17 December 2011 - 01:56 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=260139&amp;s=415c0523a5fe4a29ee4ee37652cfa78e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 lemonco

Reputation: 0
• Posts: 4
• Joined: 16-December 11

# Questions I got wrong on my final.

Posted 16 December 2011 - 10:37 AM

Hey, I got a few questions wrong on my final. I can't really do anything about it at the moment, but I was wondering if someone could explain how I got them wrong so it could help me next semester and not keep me up at night.

int x, y = 2;
float z= 4.2;
x = y * z;

The value stored in x is..

I put 8.4 xP

2. A ______ expression is using greater-than, less-than, greater-than-or-equal-to,etc.
I put mathematical

3.
how many times "hello world" will print out
for ( int i = 0; i < 5; i++)
for ( int j = 0; j < 5; j++)
cout << "hello world" << endl;

4. mathematical operators in c/c++ are evaluated in a specific order, which is correct?
i put multiplication/division/mod, addition/subtraction, unary operators

help on any of these will be great! thanks

Is This A Good Question/Topic? 0

## Replies To: Questions I got wrong on my final.

### #2 r.stiltskin

• D.I.C Lover

Reputation: 2034
• Posts: 5,436
• Joined: 27-December 05

## Re: Questions I got wrong on my final.

Posted 16 December 2011 - 10:43 AM

The teacher told you you were wrong but wouldn't tell you the correct answers?

### #3 lemonco

Reputation: 0
• Posts: 4
• Joined: 16-December 11

## Re: Questions I got wrong on my final.

Posted 16 December 2011 - 10:45 AM

no, it was an electronic test via computer

### #4 r.stiltskin

• D.I.C Lover

Reputation: 2034
• Posts: 5,436
• Joined: 27-December 05

## Re: Questions I got wrong on my final.

Posted 16 December 2011 - 10:48 AM

For #1, you forgot that x is an int. Now, what do you think the answer is?

For #3, what do you think?

For #2 and #4, were these multiple choice questions? If so, what were the choices?

### #5 lemonco

Reputation: 0
• Posts: 4
• Joined: 16-December 11

## Re: Questions I got wrong on my final.

Posted 16 December 2011 - 10:52 AM

r.stiltskin, on 16 December 2011 - 10:48 AM, said:

For #1, you forgot that x is an int. Now, what do you think the answer is?

For #3, what do you think?

For #2 and #4, were these multiple choice questions? If so, what were the choices?

sorry, this is my first class in programming and it's an online class, so i can't explain it in complex terms so excuse my simple wording.

#1, x must be 2 because it's declared as an int

#2 i really don't remember the choices. our teacher gives us the one we got wrong but not the answer.

#3 i put 4

#4 it was those three (multi/div/mod, add/sub, unary operators) <- but i had to put them in order by which came first

### #6 sepp2k

• D.I.C Lover

Reputation: 2756
• Posts: 4,416
• Joined: 21-June 11

## Re: Questions I got wrong on my final.

Posted 16 December 2011 - 11:01 AM

#1 Why 2? That makes no sense at all.

#2 As far as I'm concerned x < y is a mathematical expression (though the term isn't really well defined), but so are x + y and other arithmetic expressions, which weren't mentioned. So I'm assuming the options also included a more specific term that would not also apply to x + y (like say: "comparisons" or "boolean expressions").

#3 First of all a for loop from 0 (inclusive) to 5 (exclusive) will execute 5 times, no 4. Second you need to notice that the two loops are nested. I.e. on each iteration of the outer loop the inner loop will execute 5 times.

#4 Do you think - 4 + 5 * 6 is equivalent to - (4 + (5 * 6)) or (-4) + (5*6)?

### #7 r.stiltskin

• D.I.C Lover

Reputation: 2034
• Posts: 5,436
• Joined: 27-December 05

## Re: Questions I got wrong on my final.

Posted 16 December 2011 - 11:05 AM

#1: When a floating point value is assigned to an int variable, it is truncated, which means the fractional part is discarded and the int is assigned the whole-number part. So 8.4 becomes 8 and that becomes the value of x.

#2 is a little ambiguous. It might be 'boolean' or 'comparison' or 'loop control'. Are any of those familiar? Depends on what choices were offered.

#3: How did you get 4? Describe how you think the loops work.

This post has been edited by r.stiltskin: 16 December 2011 - 11:06 AM

### #8 jjl

• Engineer

Reputation: 1271
• Posts: 4,998
• Joined: 09-June 09

## Re: Questions I got wrong on my final.

Posted 16 December 2011 - 11:25 AM

Quote

It might be 'boolean' or 'comparison' or 'loop control'

Those are a little ambiguous, since these are mathamatical relationships - not all of order - I would consider them relational operators.

This post has been edited by Loundy: 16 December 2011 - 11:36 AM

### #9 Martyr2

• Programming Theoretician

Reputation: 5509
• Posts: 14,498
• Joined: 18-April 07

## Re: Questions I got wrong on my final.

Posted 16 December 2011 - 11:41 AM

2) I think the word they wanted is "relational". While relational expressions are mathematical in nature, one could argue that relations are also a piece of philosophy as much as they are mathematical. What is the definition of value? How might value be determined? But the word they wanted was relational since those operators are called relational operators and are used to create relational expressions.

### #10 Karel-Lodewijk

Reputation: 455
• Posts: 864
• Joined: 17-March 11

## Re: Questions I got wrong on my final.

Posted 16 December 2011 - 12:59 PM

1)8, you forgot the cast to int
2)in C++ they are referred to as boolean expressions
3)25
4)unary takes preference over the arithmetic ones

### #11 lemonco

Reputation: 0
• Posts: 4
• Joined: 16-December 11

## Re: Questions I got wrong on my final.

Posted 17 December 2011 - 01:56 AM

Oh..I figured some of them out when I went back to my professor! I'm so sorry for wasting time. Thank you so much though! Really!