Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . What is the printout of the following switch statement? char ch = ' a ' ; switch ( ch ) { case '

1. What is the printout of the following switch statement?
char ch ='a';
switch (ch)
{
case 'a':
case 'A':
cout << ch << endl; break;
case 'b':
case 'B':
cout << ch << endl; break;
case 'c':
case 'C':
cout << ch << endl; break;
case 'd':
case 'D':
cout << ch << endl;
}
a. ab
b. a
c. abcd
d. aa
2. What is the printout of the following code?
#include
using namespace std;
void f(int &p1, int p2)
{
p1++;
p2++;
}
int main()
{
int x1=1;
int x2=1;
f(x1, x2);
cout <<"x1 is "<< x1<<" x2 is "<< x2;
}
a. x1 is 2 x2 is 1
b. x1 is 2 x2 is 2
c. x1 is 1 x2 is 1
d. x1 is 1 x2 is 2
3. The following code displays ______________.
#include
using namespace std;
void maxValue(int value1, int value2, int max)
{
if (value1> value2)
max = value1;
else
max = value2;
}
int main()
{
int max =0;
maxValue(1,2, max);
cout << "max is "<< max << endl;
return 0;
}
a. max is
b. max is 1
c. max is 0
d. max is 2
4. What is the output of the following code?
#include
using namespace std;
void f(double &p)
{
p +=2;
}
int main()
{
double x =1;
double y =1;
f(x);
f(y);
cout <<"x is "<< x;
cout <<" y is "<< y << endl;
return 0;
}
a. x is 2 y is 1
b. x is 3 y is 3
c. x is 2 y is 2
d. x is 1 y is 1
e. x is 1 y is 2
5. The following program invokes p() three times. What is the printout from the last call of p()?
#include
using namespace std;
int j =40;
void p()
{
int i =5;
static int j =5;
i++;
j++;
cout <<"i is "<< i <<" j is "<< j << endl;
}
int main()
{
p();
p();
p();
}
a. i is 6 j is 8
b. i is 6 j is 6
c. i is 6 j is 9
d. i is 6 j is 7
6. Given the following two arrays:
char s1[]={'a','b','c'};
char s2[]= "abc";
Which of the following statements is correct?
a. s1 has three characters
b. s2 has three characters
c. s2 has four characters
d. s1 has four characters
7. Analyze the following code:
int main()
{
int x[5];
int i;
for (i =0; i <5; i++)
x[i]= i;
cout << x[i]<<"";
return 0;
}
a. The program may have a runtime error because the last statement in the main function has the out of bound index for the array.
b. The program displays 4.
c. The program has a compile error because i is not defined in the last statement in the main function.
d. The program displays 01234.
e. The program might displays a random number
8. Show the output of the following code:
#include
using namespace std;
void increase(int x[], int size)
{
for (int i =0; i < size; i++)
x[i]++;
}
void increase(int y)
{
y++;
}
int main()
{
int x[]=
{
1,2,3,4,5
};
increase(x,5);
int y[]=
{
1,2,3,4,5
};
increase(y[0]);
cout << x[0]<<""<< y[0];
}
a.22
b.11
c.12
d.00
e.21
9. Suppose you declare
char city[7]= "Dallas";
How many characters are stored in city?
a.7
b.5
c.8
d.6
10. What is the printout of the following code?
char s2[7]= "Dallas";
char s1[14]= "Dallas";
strcat(s1, s2);
cout << s1;
a. Dallas
b. DD
c. DallasDallas
d. D
11. When you pass an array to a function, the function receives __________.
a. a copy of the array
b. the reference of the array
c. the length of the array
d. a copy of the first element
12. What is the output of the following code?
#include
using namespace std;
int main()
{
int matrix[4][4]=
{{1,2,3,4},
{4,5,6,7},
{8,9,10,11},
{12,13,14,15}};
int sum =0;
for (int i =0; i <4; i++)
cout << matrix[i][1]<<"";
return 0;
}
a.13812
b.361014
c.4567
d.1234
e.25913

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

LO1 Explain how the workforce is changing in unpredicted ways.

Answered: 1 week ago