C++ Intermediate Quiz

1. What is the correct way to declare a function in C++?

a) void myFunc() {}
b) def myFunc():
c) function myFunc() {}
d) myFunc() {}

2. What does `std::vector v;` declare?

a) An array of integers
b) A dynamic array of integers
c) A pointer to integers
d) A single integer

3. True or False: Pointers can store memory addresses.

a) True
b) False

4. What is the output of `int x = 5; int* p = &x; cout << *p;`?

a) Address of x
b) 5
c) &x
d) Error

5. How do you access the first element of `std::vector v = {1, 2, 3};`?

a) v[0]
b) v.first()
c) v.at(1)
d) v.get(0)

6. What is the purpose of `const` in `void func(const int x)`?

a) Makes x global
b) Prevents x from being modified
c) Makes x a pointer
d) Initializes x to 0

7. What does `v.push_back(4);` do for a vector?

a) Removes 4
b) Adds 4 to the end
c) Replaces the last element
d) Clears the vector

8. True or False: Arrays in C++ are always passed by reference.

a) True
b) False

9. What is the output of `int arr[3] = {1, 2, 3}; cout << arr[3];`?

a) 3
b) Undefined
c) 0
d) Error

10. What does `&` mean in `int& ref = x;`?

a) Pointer
b) Reference
c) Address
d) Constant