Quiz5 and Solutions

Quiz5 and Solutions - Computer Techniques for Electronic...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Computer Techniques for Electronic Design II (ESE 224) Quiz for chapter 5 Period: 10 minutes Multiple Choice Problems 1. Which of the following statements about function is true? a) The body of a function is contained in braces; b) All objects(variables) used by a function is contained in the parameter list; c) A function cannot change the value of an function argument; d) A program can use both pre‐defined functions and programmer‐defined functions; e) If a static object is declared inside a function, it can only be accessed within the function. 2. Which of the following is a valid function prototype? a) void function cube(double x); b) function cube (double x); c) void cube (double x); d) cube (double x); e) void cube(double); Program Analysis For question 3 ~ 5, write down the value of a and b after the execute of main ( ) 3. void swap(int a, int b) { int c; c = a; a = b; b = c; return; } int main() { int a(2),b(3); swap(a,b); return 0; } 4. void swap(int *a, int *b) { int c; c = *a; *b = *a; //The value of *b is unchanged within this function *a = c; return; } int main() { int a(2),b(3); swap(&a,&b); return 0; } 5. void swap(int &a, int &b) { int c; c = a; a = b; b = c; return; } int main() { int a(2),b(3); swap(a,b); return 0; } 6. Write down the value of x after execution of main() #include <iostream> using namespace std; int x = 5; int test(int x) { x = x + 1; return x; } int main() { int x = 0,y; y = test(x); x = test(x); cout << x << endl; } Solutions 1. 2. 3. 4. 5. 6. A,D,E C,E 2,3 2,2 3,2 1 ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online