1. A function type is defined by the 2. An argument passed to a function can 3.
ID: 641856 • Letter: 1
Question
1. A function type is defined by the
2. An argument passed to a function can
3. If a function does not expect an argument, the function's prototype can be declared
4. To make the identifiers of the std namespace globally available in your program, you can add the directive____________.
5. Given the declarations
double myFunc(int, double);
short a = 2;
when the function is called
myFunc( a, a/3)
6. Given the prototype
void drawTo(double x, double y, color = 1);
the function drawTo( ) can be called
7. The scope of function parameters applies to
8. Functions can be defined in any order.
9. If more parameters are declared in the function header than arguments passed to the function when it is called, the remaining parameters are initialized with default values.
10. Every function definition must contain at least one return statement.
11. If the return type of a function is void, the function block cannot contain a return statement.
12. Given the declarations
void func( double); double x = 5.5;
when control exits the function call
func(x);
the value of x may have changed.
13. If a function definition contains several return statements, the program flow branches back as soon as
14. Given the function definition
int func(void)
{
static int x = 0;
return ++x;
}
after the third call, the function func() returns the value ______.
15. When defining a reference to an object, use the character ______ preceding the name of the reference.
16. When a function is called and an object is passed by reference, the object ______ is passed internally.
17. Given the definitions
int x = 10, *px = &x;
you can access the variable x via the pointer px using the expression ______ .
18. You can distinguish the redirection operator * from the multiplication operator * by the ______ of operands.
19. Suppose that the function revers( ) manipulates a string. As an argument, it requires the address of a string type object and it returns no value. In this case, the prototype of the function is ______.
20. A function can use reference parameters to return multiple values to the calling function.
21. Given the definitions
int a = 2, b = 3, c = 4;
the expression
a += b *= c
22 Following the declaration
double* ptr;
you must assign to ptr
23 Given the declarations
void func(double* p1, double* p2);
double x = 1.1, y = 2.2;
you can call the function func() using
24. In the equation x = y % z, y and z are both int. Variable x is a double, y = 35, and z = 6. What will be the value of the variable x?
a. x = 4.0000000000
b. x = 5.0000000000
c. x = 5.6666666667
d. x = 6.0000000000
25. Which if statement would be true if you needed to see if x (an int) is less than 25?
a. if ( x > 0 && x < 25 )
b. if ( x <= 24 )
c. if ( x <= 25 )
d. if ( x > 26 )
26. Which of the symbols below is a logical operator?
a. >
b. | |
c. = =
d. !=
27. The length of a string is discovered by a call to the size( )operation.
28. (9 points) write the shortest C++ code.
Program to display user name,
29. (9 points) Write a C++ code that includes the following operations:
z=x+y
z=z/3.0
x, y, and z are floating point variables. A function (subroutine) named GetData should be declared to get data from keyboard.
The call by reference (pointer) mechanism should be used in Get Data function!
Explanation / Answer
1-2
2-3
3-2
4-3
5-2
6-3
7-1
8-1 (they have to be declared in proper order, but the full definitions of the body of functions can be done in any order)
9-1
10-2
11-1
12-2
13-1
14-3
15-1
16-1
17-1
18-1(redirection * is unary, other one is binary operator)
19-1
20-2 (the scope of the variables in the function are over once you exit the function. So, you cannot return their refference as they will no longer be there after the function exits)
21-2
22-3
23-2
24-b
25-b
26-b
27-1
28-
#include<stdio.h>
int main()
{
printf("Username");
return 0;
}
29-
#include<stdio.h>
void GetData(int&);
int main()
{
int x,y;
GetData(x);
GetData(y);
float z=x+y;
z=z/3.0;
printf("%f",z);
return 0;
}
void GetData(int &x)
{
scanf("%d",&x);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.