CPP_MTE_Questions
CPP_MTE_Questions
int i = 1;
for(; i <= 5; i++) {
if (i % 2 == 0) continue;
cout << i << ' ';
}
A) 1 3 5
B) 1 2 3 4 5
C) 1 2 4
D) 2 4
E) Compilation error
3. Which of the following for loops is equivalent to the while loop below?
int i = 0;
while(i < 5) {
cout << i << ' ';
i++;
}
A) 0 1 0 1 0 1
B) 0 0 0
C) 0 1 0 1
D) 0 0
E) Compilation error
int function()
{
int a;
a = 250;
}
A) 10
B) 5
C) Compilation error
D) Undefined behavior
E) Segmentation fault
int main() {
cout << func(1);
}
A) 6
B) 5
C) 7
D) Compilation error
E) 1
int main()
{
double x = 2, y = 2, z;
z = mysteriousFunction(x, y);
cout << z;
}
A) 2
B) 3
C) 5
D) Compilation error
E) None
A) True
B) False
C) Compilation error
D) Undefined behavior
E) No output
________________________________________________________________________________
21. If the following program does not compile, why not? If it does compile, what
is the output when it is run?
#include <iostream>
using namespace std;
int main()
{
char ch = '0';
ch++;
cout << ch << endl;
cout << (int)ch << endl;
ch += 7;
cout << ch << endl;
cout << (int)ch << endl;
int n = ch;
cout << n << endl;
cout << (char)n << endl;
int m = ch - '3';
cout << m << endl;
}
22. If the following program does not compile, why not? If it does compile, what
is the output when it is run?
#include <iostream>
using namespace std;
int main()
{
for(int month = 1;month<3;month++)
{
switch(month)
{
case 1: cout << "Two roads diverged in a wood.";
break;
case 12: cout << "I took the one less travelled by,";
break;
case 3: cout << "and that has made all the difference.";
break;
default: cout << "?";
}
}
}
23. If the following program does not compile, why not? If it does compile, what
is the output when it is run?
#include <iostream>
using namespace std;
int main()
{
const int SIZE = 100;
int score[ SIZE ], i, min;
cout << "Minimal value is: " << min << endl;
}
24. If the following program does not compile, why not? If it does compile, what
is the output when it is run?
#include <iostream>
using namespace std;
int main()
{
const int SIZE = 3;
int arr[SIZE][SIZE] = { {1,2,3}, {4,5,6}, {7,8,9} };
int main()
{
const int SIZE = 10;
int x[ SIZE ] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
int y = 2;
int main()
{
int x = 1, y = 1;
double a = 1.0, b = 1.0;
output(x,y);
output(a,b);
output(x,b);
output(a,x);
output(a,y);
}
27. The following program does not compile. Where are the compilation errors at?
(1 marks)
#include <iostream>
using namespace std;
int main()
{
int @__#__#__@; // (1)
////////////////////////////////// // (11)