Q.1 How is an array initialized in C language?
(A) int a[3] = {1, 2, 3};
(B) int a = {1, 2, 3};
(C) int a[] = new int[3]
(D) int a(3) = [1, 2, 3];
Q.5 From following which is not the operation of data structure?
(A) Operations that manipulate data in some way
(B) Operations that perform a computation
(C) Operations that check for syntax errors
(D) Operations that monitor an object for the occurrence of a controlling event
Q.6 What will be the output of the following code snippet?
void solve() {
int a[] = {1, 2, 3, 4, 5};
int sum = 0;
for(int i = 0; i < 5; i++) {
if(i % 2 == 0) {
sum += a[i];
}
}
cout << sum << endl;
}
(A) 5
(B) 6
(C) 9
(D) 4
Q.7 What will the output of the following code snippet?
void solve() {
int a[] = {1, 2, 3, 4, 5};
int sum = 0;
for(int i = 0; i < 5; i++) {
if(i % 2 == 0) {
sum += *(a + i);
}
else {
sum -= *(a + i);
}
}
cout << sum << endl;
}
(A) 7
(B) 5
(C) Syntax error
(D) 3
Q.8 What is the disadvantage of array data structure?
(A) The amount of memory to be allocated should be known beforehand.
(B) Elements of an array can be accessed in constant time.
(C) Elements are stored in contiguous memory blocks.
(D) Multiple other data structures can be implemented using arrays.
Q.9 How are String represented in memory in C?
(A) The object of some class.
(B) An array of characters.
(C) Same as other primitive data types.
(D) LinkedList of characters.
Q.10 What is the output of the following code snippet?
void solve() {
stack s;
s.push(1);
s.push(2);
s.push(3);
for(int i = 1; i <= 3; i++) {
cout << s.top() << “ “;
s.pop();
}
}
(A) 3 2 1
(B) 1 2 3
(C) 3
(D) 1