Computer Programming 1
Computer Programming 1
1
int* ptr = arr;
B. a) 5
C. b) 10
D. c) 15
E. d) Compiler error
#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.
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;
10. What are the values of a, b, and c after this code executes?
int a = 5, b = 10, c;
c = a++ + --b
bool z = x & y;
A) Error
B) z = true
C) z = false
D) None
B) Function overloading is a technique in C++ that allows defining multiple functions with
the same name but different numbers or types of parameters.
3
D) Function overloading is a way to create functions inside other functions to achieve better
code organization.
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.
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
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
if (x == 7)
continue;
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