Question

2. Consider the following program written in C syntax: void swap(int a, int b) {   ...

2. Consider the following program written in C syntax:

void swap(int a, int b) {
   int temp;
   temp = a;
   a = b;
   b = temp;
}
void main() {
   int value = 2, list[5] = {1, 3, 5, 7, 9};
   swap(value, list[0]);
   swap(list[0], list[1]);
   swap(value, list[value]);
}

For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three calls to swap?

a. Passed by value

b. Passed by reference

c. Passed by value- result

d. Passed by name

Homework Answers

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ questions 5.Which of the following function prototype(s) are correct. void setValue(int &value); void setValue(int &);...
C++ questions 5.Which of the following function prototype(s) are correct. void setValue(int &value); void setValue(int &); void setValue(int value, int max=100); void setValue(int ++value); 6. T/F Calling an overloaded function can result in multiple values being returned to the caller. 7.A ____ function has ____ return value(s), but can have ____ parameter(s). Otherwise a function can return _____ value(s). 8.T/F Only variables can be passed as reference. 9.T/F When writing a C++ program you must be careful to arrange all...
4. Consider the following program, written in JavaScript-like syntax: // main program var x, y, z...
4. Consider the following program, written in JavaScript-like syntax: // main program var x, y, z function sub1() { var a, y, z; . . . } function sub2() { var a, b, z; . . . } function sub3() { var a, x, w; . . . } Given the following calling sequences and assuming that dynamic scoping is used, what variables are visible during execution of the last subprogram activated? Include with each visible variable the name of...
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
C program. Given the following code: int add_and_double(int a, int b) { int result = (a...
C program. Given the following code: int add_and_double(int a, int b) { int result = (a + b) * 2; return result; } int main() {   int val; val = add_and_double(12, 40); return 0; } where the function main() (i.e. the caller) calls the function add_and_double() (i.e. the callee). Which of the following actions are taken when main() calls the function add_and_double()?  Select all that apply. a. Once the callee returns, the caller frees the stack memory for the callee's function...
A.6 ... static int x = 1; int y = x * 2; void t1() {...
A.6 ... static int x = 1; int y = x * 2; void t1() {                 y++;                 cout << "x: " << x << " | y: " << y << endl;                 y += 1;                 x -= -1; } void t2() {                 int* x = &y;                 cout << "x: " << x << " | y: " << y << endl; } void t3() {                 int y = x;                 static int x...
Given the following function in C++: int main(void) { int a = 2; int b =...
Given the following function in C++: int main(void) { int a = 2; int b = myFunction(a); a = b + 1; b = myFunction(a); cout << ”b = ” << b << endl; return 0; } int z = myFunction(int x) { static int n = 0; n = n + 1; int z = x + n; return z; } What is printed by the cout on the screen?
In C++ void func( int& num1, int* num2) {               int temp = *num2; *num2 =...
In C++ void func( int& num1, int* num2) {               int temp = *num2; *num2 = num1; num1 = temp - *num2; } Given the function definition above what would be the result of the following code? int val1 = 5; int val2 = 8; func(val1, &val2); cout << val1 << “,” << val2 << endl; Answer a) 13, 8    b) 8, 13 c) An error message d) 3, 5 e) 8, 5
Consider the following program listing that is written in the C Language: #include <msp430.h> void main(void);...
Consider the following program listing that is written in the C Language: #include <msp430.h> void main(void); { WDTCTL = WDTPW|WDTHOLD; unsigned char a=0x14; unsigned char b=0xDC; unsigned char c,d,e,f; c = a^b; d = a|b; e = ~d; f = ~e; while(1); } 1) Are the declared data types local or global variables? 2) Perform bitwise logical analysis to determine the unknown values of the given logic expressions. 3) Show the correct addresses and contents for all variables in the...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
C PROGRAMMING LANGUAGE The following code written in C programming language was run and displays 997705320....
C PROGRAMMING LANGUAGE The following code written in C programming language was run and displays 997705320. Explain why and how this program outputs this number. int main(void) { int a = 5, b =20; int* ptr = &a; int** ptr2 = &ptr; printf("%d\n", ((int)*ptr * (int)*ptr2)); return 0; }