0% found this document useful (0 votes)
5 views

Computer Programming 1

The document contains a series of multiple-choice questions related to C++ programming concepts, including the use of break statements, passing arrays to functions, recursive functions, and function overloading. It also addresses topics such as file handling, seeking file pointers, and the behavior of loops. Each question provides options for answers, testing the reader's understanding of C++ syntax and functionality.

Uploaded by

kiyadebela42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Computer Programming 1

The document contains a series of multiple-choice questions related to C++ programming concepts, including the use of break statements, passing arrays to functions, recursive functions, and function overloading. It also addresses topics such as file handling, seeking file pointers, and the behavior of loops. Each question provides options for answers, testing the reader's understanding of C++ syntax and functionality.

Uploaded by

kiyadebela42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

The break statement causes an exit from


A. the loop.
B. if statement
C. switch statement.
D. A and C
E. All of the above
2. Consider the following C++ function. What is the correct way to pass an array to the
function?
void myFunction(int arrayName[5]){ ….. }
A. myFunction(int arrayName[]);
B. myFunction(arrayName);
C. myFunction(&arrName);
D. myFunction(int* arrName)
3. What is the output of the following recursive function?
int Digits(int n) {
if (n == 0) {
return 0;
}
return n % 10 + Digits(n / 10);
}
A. The sum of the digits of the number n
B. The product of the digits of the number n
C. The reverse of the number n
D. None of the above
4. When we define the default values for a function?
A. When a function is defined
B. When a function is called
C. When a function is declared
D. When the scope of the function is over
E. A and C
5. What will happen in the following C++ code snippet?
int a = 100, b =200;
int *p = &a, *q = &b ;
p = q
A. b is assigned to a
B. p now points to b
C. a is assigned to b
D. q now points to a

9. What will be printed by this code?


int arr[3] = {5, 10, 15};

1
int* ptr = arr;

cout << *(ptr++);

B. a) 5

C. b) 10

D. c) 15

E. d) Compiler error

14. What will be the output of the following C++ code?

#include <iostream>
using namespace std;
int main() {

char arr[20];
int i;
for (i = 0; i < 10; i++)
*(arr + i) = 65 + i;
*(arr + i) = '\0';
cout << arr;

return 0;
}

A. a) ABCDEFGHIJ
B. b) AAAAAAAAAA
C. c) JJJJJJJJ
D. d) AAAAAAJJJJ

18. What is the main difference between a structure (struct) and a union (union) in C++?

a) A struct allows members to share the same memory space, while a union does not.

b) A union allows members to share the same memory space, while a struct does not.

c) A struct and a union are identical.

d) A union is used for dynamic memory allocation, while a struct is used for static
memory allocation.

2
3. What is the purpose of the following typedef declaration?
typedef unsigned long long int ULLI;

a. It defines a new struct named ULLI.

b. It creates an alias for unsigned long long int called ULLI.

c. It declares a union named ULLI.

d. It specifies a set of named integer constants.

10. What are the values of a, b, and c after this code executes?

int a = 5, b = 10, c;

c = a++ + --b

A) a=5, b=10, c=15


B) a=6, b=9, c=15
C) a=6, b=10, c=16
D) a=5, b=9, c=14

E) None of the mentioned

11. Which statement results from this code?

bool x = true, y = false;

bool z = x & y;

A) Error
B) z = true
C) z = false
D) None

20. What is concept of function overloading in C++.


A) Function overloading is a feature in C++ that allows defining multiple functions with the
same name but different return types.

B) Function overloading is a technique in C++ that allows defining multiple functions with
the same name but different numbers or types of parameters.

C) Function overloading is a practice in C++ that involves overwriting existing functions


with new functionality.

3
D) Function overloading is a way to create functions inside other functions to achieve better
code organization.

21. What is the main purpose of a base case in a recursive function?


a. To make the function call itself

b. To provide an exit condition and stop the recursion

c. To increase the efficiency of the recursive function

d. To make the function tail-recursive

22. Which of the following is a potential issue with recursive solutions in terms of efficiency and
memory usage?
a. Recursive functions are always more memory-efficient.

b. Recursive functions consume additional memory for each function call, potentially leading
to a stack overflow.

c. Recursive functions are faster than their iterative counterparts.

d. Recursive functions do not have any efficiency or memory-related concerns.

23. Where should default parameters appear in a function prototype?


a) To the rightmost side of the parameter list

b) To the leftmost side of the parameter list

c) Anywhere inside the parameter list

d) Middle of the parameter list

24. If we have object from ofstream class, then default mode of opening the file is _____ .
a. ios::in

b. ios::out

c. ios::in|ios::trunc

d. ios::out|ios::trunk

25. Which of the following is not used to seek file pointer?


a) ios::set

b) ios::end

4
c) ios::cur

d) ios::beg

26. When using the seekp() function with ios::cur as the offset, what does it do?
A. Sets the get pointer to the current position

B. Moves the put pointer relative to the end of the file

C. Moves the put pointer relative to the current position

D. Sets the put pointer to the beginning of the file

27. What will be printed by this code segment?


int x = 5;

while (x <= 10) {

if (x == 7)

continue;

cout << x << " ";

x++;

A) 5 6 7 8 9 10 C) 5 6 8 9 10 11
B) 5 6 8 9 10 D) Infinite loop E) none

You might also like