Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 2 of 2
Thread: Quick question

08302007, 10:49 PM #1
 Join Date
 Jun 2007
 Posts
 21
 Thanks
 0
 Thanked 0 Times in 0 Posts
Quick question
I would like to verify the following answers:
Given the following C++ code:
int x[10], y, z;
for (int i=0; i<9; i++)
x[i] = i+1;
y = x[8];
z = x[9];
What are the respective values for:
i=??
y=80
z=90
Given the following C++ function definition:
void foo(int a, int& b)
{ a=2; b=5; }
What would be the resulting values of the following piece of client code?
int x = 0;
int y = 0;
int a;
foo(x,y);
cout << x << a << y <<;
a=2
x=0
y=0
08302007, 11:30 PM
#2
Walk it through...Second problem...Code:// Instansiate (create) three variables of the integer type // Label them x, y and z respectively. // x is going to be a static array with 10 indices (nodes or columns). int x[10], y, z; // Next two lines go together. Use a forloop to populate x. Use an integer // labeled i as the iterator. When i is = (equal to) or > (greater than) 9, stop // looping. For each instance of the loop take the value of i (0  8), add one // to i and set the resulting value of i as the value of the i'th index of x. In // other words. First iteration of loop x[0] = (0 + 1) = 1, second iteration of // loop x[1] = (1 + 1) = 2, third iteration of loop x[2] = (2 + 1) = 3, etc. etc. for (int i=0; i<9; i++) x[i] = i+1; // Set y = (equal to) the value of the eigth index of x. y = x[8]; // Set z = (equal to) the value of the ninth index of x. z = x[9];HTH,Code:// Use a function called foo to evaluate the following: // An integer named a which is passed by value (whatever the value of a is // going into the function, a remains the same when it comes out of the // function); i.e.  foo(100, 5) returns a=100, b=5. // An integer named b which is passed by reference (whatever the value of b // is going into the function, b gets changed by the function); i.e.  // foo(5, 100) returns a = 5, b = 5 void foo(int a, int& b) { a=2; b=5; } // What would be the resulting values of the following piece of client code? // Instansiate (create) a variable of the integer type, label the integer as x // and set x's value = (equal to) 0. int x = 0; // Instansiate (create) a variable of the integer type, label the integer as y // and set y's value = (equal to) 0. int y = 0; // Instansiate (create) a variable of the integer type, label the integer as a // and leave a as undefined. int a; // Call the function foo with x and y as the parameters. foo(x,y); cout << x << a << y <<;
saige
HTML & CSS Forum Moderator
"If you don't know what you think you know, then what do you know."
R.I.P. Derrick Thomas #58
1/1/1967  2/8/2000