Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C Language (not C++) 1) When parameters are passed between the calling code and the called function, formal and actual parameters are matched by:

In C Language (not C++)

1) When parameters are passed between the calling code and the called function, formal and actual parameters are matched by: 1) their data types 2) their relative positions in the formal and actual parameter lists 3) their names 4) whether they are inputs to or outputs from the function 5) none of these

2) A parameter as a simple type for example int or double, should be passed by value if that parameter's data flow is: 1) one-way, into the function. 2) one-way, out of the function. 3) two-way, into and out of the function. 4) 1 and 2 above 5) 2 and 3 above 6) none of these

3) Given the function prototype and declarations: int Fix(int , float&); int someInt = 10; float someFloat = 4.3; which of the following function calls would be syntactically correct? 1) Fix(someInt, 6.85); 2) someFloat = Fix(24, 6.85); 3) someFloat = 0.3 * Fix(6, someFloat); 4) Fix(someInt + 5, someFloat); 5) all of the above 6) 1 and 3 above 7) 2 and 4 above 8) none of the above

4) A function SomeFunc has two formal parameters, alpha and beta, of type int. The data flow for alpha is twoway, into and out of the function. The data flow for beta is two-way, into and out of the function. What is the most appropriate function prototype for SomeFunc? 1) void SomeFunc( int alpha, int beta ); 2) void SomeFunc( int& alpha, int beta ); 3) void SomeFunc( int alpha, int& beta ); 4) void SomeFunc( int& alpha, int& beta ); 5) 1 and 2 above 6) 3 and 4 above 7) none of these

5) If an ampersand (&) is not attached to the data type of a formal parameter, then the corresponding actual parameter can be: 1) a constant 2) a variable name 3) an arbitrary expression 4) 1 and 2 above 5) 1, 2, and 3 above 6) none of the above 6) Given the function definition

void Twist( int& a, int& b ) {

int r; r = a + 2; a = a * 3; b = r + a;

}

what is the output of the following code fragment that invokes Twist? int r = 1; int s = 2; int t = 3; Twist(t, s); cout << r << ' ' << s << ' ' << t << endl; 1) 1 2 3 2) 1 2 9 3) 1 14 3 4) 1 10 3 5) 5 14 3 6) 1 14 9 7) none of the above 7) Which of the following statements about value parameters is false? 1) The actual parameter is never modified by execution of the called function. 2) The formal parameter is never modified by execution of the called function. 3) The actual parameter must be a variable. 4) The actual parameter can be a literal constant value. 5) 2 and 3 above 6) none of these 8) Which of the following statements about reference parameters is false? 1) The actual parameter can be modified by execution of the called function. 2) The formal parameter can be modified by execution of the called function. 3) The actual parameter cannot be a variable. 4) The actual parameter cannot be a literal constant value. 5) 1 and 2 above 6) none of these

9) Which of the following statements about constant reference parameters is false? 1) The actual parameter can be modified by execution of the called function. 2) The formal parameter can be modified by execution of the called function. 3) The actual parameter cannot be a variable. 4) The actual parameter cannot be a literal constant value. 5) 1 and 2 above 6) none of these

10) Consider the function definition

void Demo( int& intVal, float floatVal )

{

intVal = intVal * 2; floatVal = intVal + 3.5;

}

What values are printed by the following code fragment? int myInt = 20; float myFloat = 4.8; Demo(myInt, myFloat); cout << "myInt = " << myInt << " and myFloat = " << myFloat << endl; 1) myInt = 20 and myFloat = 43.5 2) myInt = 40 and myFloat = 4.8 3) myInt = 20 and myFloat = 4.8 4) myInt = 40 and myFloat = 43.5 5) none of the above

11) For the function definition void Func( int& gamma ) { gamma = 245; } which of the following comments best describes the direction of data flow for gamma? 1) one-way, into the function 2) one-way, out of the function 3) two-way, into and out of the function 4) none of the above

12) This question demonstrates the hazard of choosing inappropriate parameter-passing mechanisms. Given the function definition

int Power(int& base, int& exp ) { int product = 1; while (exp >= 1)

{ product = product * base; exp--; } return product; } what is the output of the following code? int n = 2; int pow = 3; int result = Power(n, pow); cout << n << " to the power " << pow << " is " << result; 1) 2 to the power 3 is 8 2) 2 to the power 0 is 8 3) 0 to the power 0 is 0 4) 2 to the power 3 is 1 5) none of the above

13) For the function definition void Func( int gamma ) { cout << 3 * gamma; } which of the following comments best describes the direction of data flow for gamma? 1) one-way, into the function 2) one-way, out of the function 3) two-way, into and out of the function 4) none of the above

14) For the function definition void Func( int& gamma ) { gamma = 3 * gamma; } which of the following comments describes the direction of data flow for gamma? 1) one-way, into the function 2) one-way, out of the function 3) two-way, into and out of the function 4) none of the above

15) If a variable alpha is accessible only within function F, then alpha is either 1) a global variable or a formal parameter of F. 2) a local variable within F or a formal parameter of F. 3) a global variable or an actual parameter to F. 4) a local variable within F or an actual parameter to F. 5) none of the above

16) Choose the correct statement: 1) A function prototype is global if it is placed outside function definitions in the source file. 2) A function prototype is local if it is placed in a function definition. 3) The scope of a global prototype begins at the point it is placed and extends until the end of the source file. 4) The scope of a local prototype begins at the point it is placed and extends until the end of the function in which it appears. 5) All of the above are correct 6) None of the above are correct

17) Suppose the first few lines of a function are as follows: void Calc( float beta ) { alpha = 3.8 * beta; Assuming the code compiles, then the variable alpha is 1) a local variable 2) a global variable 3) a parameter 4) none of the above

18) What is the output of the following code fragment? int alpha = 3; int beta = 20; if (beta > 10) { int alpha = 5; beta = beta + alpha; cout << alpha << ' ' << beta << ' '; } cout << alpha << ' ' << beta; 1) 3 20 2) 3 25 3 25 3) 5 25 5 25 4) 5 25 3 25 5) 5 25 3 20 6) none of the above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is a core competency?

Answered: 1 week ago

Question

(1 point) Calculate 3 sin x cos x dx.

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago