Overclock.net banner
1 - 6 of 6 Posts

·
Registered
Joined
·
1,771 Posts
Discussion Starter · #1 ·
I am trying to study for a programming test, I was wondering if anyone could provide the correct answers to these questions for me. Since the answers are not provided, I want to check if my answers are correct. Thanks




 

·
Registered
Joined
·
1,180 Posts
If indeed it is a practice test, I would ask the teacher for more information.

Hints:
1.) Silly question. But easy if you recall operator precedence. Or rather, one of the operators doesn't "fit" into the equations.
2.) Order of operations.
3.) Simple syntax question. What can a variable not contain, start with, or copy?
4.) Run-time errors happen during program execution.
5 & 6 are pretty straightforward
7.) It's a trick!
8.) Assignment vs. Comparison operators.
9.) What units do the sin(x) function deal in?
10.) refer here
11.) Difference between pass-by-reference and pass-by-value
12.) Two things: the (b>a) ? b:a reads as if(b>a) then b else a. Second, a double to integer cast doesn't round up or down.
13.) I've never outputted a bool type before, try it and see what happens.
 

·
Registered
Joined
·
2,017 Posts
Quote:

Originally Posted by dharmaBum View Post
7.) It's a trick!
I would've gotten that wrong if you hadn't said that.

Anyway, Oblivion77, we don't want to simply give you the answers. You should provide your answers and explain why. If you find you can't explain why, maybe that's something to look at.
 

·
Registered
Joined
·
821 Posts
Why is #7 a trick?
'n' will hit the case statement, be decremented, fall through to the next case statement and be decremented again.
 

·
Registered
Joined
·
1,771 Posts
Discussion Starter · #6 ·
Number 7 never tricked me, there wasn't a break after case(22) so it would be decremented again. However, I am a bit confused for cout <<sin(90) is the answer 0? sin(90) = 0.893997 if I make a program using it. But will it get truncated? Or is the answer none of the above? Or rounded to 1?

Number 3 - int _22_; and float I_NEED_$$$; both compile, which one is wrong?
 
1 - 6 of 6 Posts
Top