Quick Multiple Choice Problems

Posted 18 April 2013 - 05:06 PM

Hello,

I am taking an introduction to C course at college, and we were recently assigned homework problems that consisted of around 10 multiple choice problems. Since I can't post them below, I attached the problems to a PDF file. Below I will post my solutions. It would be greatly appreciated if you could help me out. Also, please do explain the answers because I am looking to actually understand the concepts

1) Not sure.

2) I have A because it is performing the formula 5-i, and the for statement is starting with i = 0 and ending with i=5.

3) I have B, since it is calling numbers from 0 to 9, then adding 1.

4) Not sure.

5) I have C. After 1 and 2, it will be forced to generate 3 zeros because x[5] is stating that the array has 5 integers.

6) I think it is C, but not sure.

7) I have A.

8) Not sure.

9) I have C because the statement is calling numbers from 0 to 5, and then adding 1.

Re: Quick Multiple Choice Problems

Re: Quick Multiple Choice Problems

Posted 19 April 2013 - 07:06 AM

Looks like he did. Remember: text is the default format of the internet. Posting a picture is useless to someone who's blind, or who disables images for any number of good reasons. Text always works. Post text.

So for the problems you're not sure about, probably it's best for you to start by analyzing the statements and reasoning through them.
You could also try executing them, I suppose, and observing their behavior, but it's probably better to start with a hyptothesis.

For example:
1) Given the statement:
int i = 10*(rand()/(double)RAND_MAX)-5;
i will be in the range:
a) -10 ≤ i ≤ 10 10 ≤ i ≤ -5
c) -5 ≤ i ≤ 10
d) -5 ≤ i ≤ 5
e) None of the above

What does rand() return? The function is defined: what does the definition say? What is the definition of RAND_MAX? What is the order of evaluation of these terms?

If you answer those questions, you should be able to answer this question without guessing.