What is the keyword used to create a structure?
struct
What symbol is used to declare a pointer?
*
How do you declare an integer array called 'arr' with 5 elements?
int arr[5];
How do you find the sum of 2 and 3 using a function with this prototype?
int sum(int a, int b);
sum(2,3);
How do you declare the library that allows you to use cin and cout?
#include <iostream>
How do you declare a private member variable for a class?
private:
int var1;
How do you assign the address of variable x to pointer ptr?
ptr = &x;
What are the indexes of the elements of an array of length 4?
0, 1, 2, 3
How do you return a value in a void function?
You don't, so you can do 'return;' or leave it blank.
What keyword is used to define a constant variable?
const
How do you access a public member variable outside a class?
className.var1
How do you allocate memory for a single integer using C++'s new operator?
int *ptr = new int;
How do you assign the value 10 to the third element in an array?
arr[2] = 10;
What is it called when you have two functions that have the same name but differ in how many parameters they have?
Function overloading
What keyword is used to exit from a loop early?
break
How do you declare a member function inside a class?
void className::func1(int var1) {
// function code
}
What C++ keyword is used to deallocate memory allocated by the new operator?
delete
How do you access the value of the fourth element of the array using the pointer 'ptr' in C++?
*(ptr + 3)
What is the syntax to pass a pointer as an argument to a function in C++?
void functionName(int *ptr) { // function code }
How do you add an element to a vector?
What does the constructor do and how do you declare it?
It initializes all of a class's member variables when the class is being created. It's declared like this
className::className() {
// constructor code
}
How do you access the nth element of an array using a pointer ptr in C++?
*(ptr + n - 1)
How do you declare a pointer 'ptr' pointing to the first element of the array 'arr' in C++?
int *ptr = arr; or int *ptr = &arr[0];
Declare a function that takes an array as its parameter.
void function1(int arr[], int size) {
// function code
}
What file stream would you use if you were trying to print your calculations out into a file?
ofstream