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.

1. One was about

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

# Questions I got wrong on my final.

Page 1 of 1## 10 Replies - 836 Views - Last Post: 17 December 2011 - 01:56 AM

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

### #2

## 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

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

Posted 16 December 2011 - 10:45 AM

no, it was an electronic test via computer

### #4

## 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?

For #3, what do you think?

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

### #5

## 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?

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

## 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

#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)?

#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

## 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

#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.

#4: google "c++ operator precedence"

*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.

#4: google "c++ operator precedence"

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

### #8

## 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

## 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

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

Posted 16 December 2011 - 12:59 PM

Most of them are presumably answered already but I'd say

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

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

## 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!

Page 1 of 1