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
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 =...
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; }
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
In Java Let’s say we’re designing a Student class that has two data fields. One data...
In Java Let’s say we’re designing a Student class that has two data fields. One data field, called id, is for storing each student’s ID number. Another data field, called numStudents, keeps track of how many Student objects have been created. For each of the blanks, indicate the appropriate choice. id should be   public/private   and   static/not static . numStudents should be   public/private   and   static/not static . The next three questions use the following class: class Counter {     private int...
Create a memory diagram for the following C program for the second time the program reaches...
Create a memory diagram for the following C program for the second time the program reaches point one. int foo(const char *x, int y); int main(void) { int a, b; a=foo("abcde", 'p'); b=foo("purple", 't'); return 0; } int foo(const char *x, int y) { int c = -1, i = 0; while (x[i] != '\0') { if (x[i] == y) i++; } //point 1 return c; }
using System; public static class Lab5 { public static void Main() { // declare variables int...
using System; public static class Lab5 { public static void Main() { // declare variables int inpMark; string lastName; char grade = ' '; // enter the student's last name Console.Write("Enter the last name of the student => "); lastName = Console.ReadLine(); // enter (and validate) the mark do { Console.Write("Enter a mark between 0 and 100 => "); inpMark = Convert.ToInt32(Console.ReadLine()); } while (inpMark < 0 || inpMark > 100); // Use the method to convert the mark into...
Write a C function to compute the following output (int) based on two input (int) variables:...
Write a C function to compute the following output (int) based on two input (int) variables: output = a*a + b*b - 2*a*b If the value of output is '0', then return -1 instead. Call the C function 4 times from main() with values of 'a' and 'b' as follows and print output values for each case. a = 3, b = 4 a = 1, b = 1 a = -2 b = 3 a = -4 b =...