Pretest (Finals)
Pretest (Finals)
Pretest (Finals)
Instructions: For each question, encircle the letter of the correct best answer.
1. What will be the output of the following C++ code?
#include <iostream>
int main () {
int n ;
cout << n;
if (n == 3)
break;
return 0;
a) 543
b) 54
c) 5432
d) 53
int main () {
int a = 10;
if (a = 15)
{ time;
cout << a;
if (n == 3)
goto time;
} break;
return 0;
a) 1010
b) 10
c) infinitely print 10
d) compile time error
URL: snsu.edu.ph
int main () {
int n = 15;
for (; ;)
cout << n;
return 0;
a) error
b) 15
c) infinite times of printing n
d) none of the mentioned
int main () {
int i;
cout << i;
return 0;
a) 0123456789
b) 10
c) 012345678910
d) compile time error
6. Which looping process is best used when the number of iterations is known?
a) While loop
b) For loop
c) Do while loop
d) all looping processes require that the iterations be known
7. Which of the following must be present in the switch construct?
a) Expression in ( ) after switch
b) default
c) case followed by value
d) All of the above
17. A switch construct can be used with which of the following types of variable?
a) int
b) int, char
c) int, float, char
d) Any basic datatype
19. If you wanted to start from 100 and loop to 3 in C++, what syntax should be
used?
a) for(int i = 0; i < 100; i+3) {}
b) for(int i = 3; i > 100; i--) {}
c) for(int i = 100; i < 3; i++) {}
20. Examine the following C++ code. What is most likely to happen with this loop?
int i = 1;
i++;
Instructions: For each question, encircle the letter of the correct best answer.
C. heterogeneous data
D. Both A and C
A. Operator
B. Variable
C. index
D. Pointer
A. Row
B. Column
A. Dynamic Memory
B. Static Memory
C. Both A and B
D. int arr[4];
A. -1
B. 0
C. 1
D. infinite
A. sizeof(array)
B. array.len
C. array.length
D. array.sizeof()
A. Code Optimization
B. Random access
C. Size No-Limit
D. Both A and B
A. Random
B. Sequential
D. Binary search
const int SIZE =5; float scores[SIZE]; for(int i=0; i<=SIZE;i++) { cout << "Enter a score\n"; cin >>
scores[i]; }
12. What is the output of the following code fragment? int array[4][4], index1, index2;
for(index1=0;index1<4;index1++) for(index2=0;index2<4;index2++) array[index1][index2]=index1 +
index2; for(index1=0;index1<4;index1++) { for(index2=0;index2<4;index2++) cout <<
array[index1][index2] << " "; cout << endl; }
A. 0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6
B. 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
C. 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3
D. 0 0 0 0 0 1 2 3 0 2 4 6 0 3 6 9
#include <iostream>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main() {
for (temp = 0; temp < 5; temp++){
result += array1[temp];
}
for (temp = 0; temp < 4; temp++){
result += array2[temp];
}
cout << result;
return 0;
}
a) 6553
b) 6533
c) 6522
d) 12200
14. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0; n < 8; n++){
result += array[n];
}
cout << result;
return 0;
}
a) 25
b) 26
c) 27
#include <iostream>
using namespace std;
int main() {
char str[5] = "ABC";
cout << str [3];
cout << str;
return 0;
}
a) ABC
b) ABCD
c) AB
d) AC
Name: Marc Jhon A. Benzal Course: ES 132
Program and Year: BSCE 2A Instructor: Ma’am Anne Say Morite
Instructions: For each question, encircle the letter of the correct best answer.
1. Which of the following function / types of function cannot have default parameters?
A. Member function of class
B. Main()
C. Member function of structure
D. Both B and C
3. What is the scope of the variable declared in the user defined function?
A. Whole program
B. Only inside the {} block
C. The main function
D. None of the above
4. Which of the following in Object Oriented Programming is supported by Function overloading and
default arguments features of C++.
A. Inheritance
B. Polymorphism
C. Encapsulation
D. None of these
A. 3.14
B. 3.15
C. 3
D. 3.1
6. Which of the following statement is correct?
A. Only one parameter of a function can be a default parameter.
B. Minimum one parameter of a function must be a default parameter.
C. All the parameters of a function can be default parameters.
D. No parameter of a function can be default.
9. Inline functions may not work. i) If function contain static variables. ii) If function contain
global and register variables. iii) If function returning value consists looping construct (i.e. for, while).
iv) If inline functions are recursive. v) If function contains const value.
A. Only i,iv & v
B. Only ii,iii & v
C. Only i,iii & iv
D. All of the above
#include <iostream>
using namespace std; void find()
void find()
{
cout<<"course";
}
int main()
{
find(); return 0;
}
A. course
B. coursecourse
C. compile time error
D. none of the mentioned
A. 10
B. 20
C. compile time error
D. none of the mentioned
A. New value of p is 5
B. New value of p is 30
C. New value of p is 15
D. None of the above
15. Which of the following is true about the following program Note: Include all required header
files.
A. 6
B. 24
C. segmentation fault
D. compile time error
A. 7
B. 13
C. 91
D. 1
19. What will be the output of the following program?
#include <iostream>
using namespace std; void lfc(int p)
{
cout << p;
}
void lfc(double q)
{
cout << q;
}
int main(void)
{
lfc(5);
lfc(555.263);
return 0;
}
A. 5555.263
B. 555.2635
C. 555.263
D. None of the mentioned
A. 10.0 5.0
B. 5.0 2.5
C. 10.0 5
D. 10 2.5