What would the data type be for a variable that holds the message "I love coding!" ?
string
Given an integer N. Your task is to check if the integer is greater than, less than or equal to 5. What kind of conditional statement do you use?
if statement
for (int i = 0; i<5; i++) {
cout << i << " ";
}
What is the output?
0 1 2 3 4
How do you access the fourth element of an array named "numbers"?
numbers[3]
What's the name of the variables that go in the paranthesis when you call a function? (ex: myfunction(thisvariable) )
parameter
What are the keywords for inputs and outputs?
cin and cout
in1 = True
in2 = True
in3 = False
out = not (in1 and not in2) or in3
What does 'out' end up outputting?
True
What is the "break" and "continue" keywords used for?
In a 2D array what is the first number and the second number in the declaration a depiction of?
The first number is the number of arrays and the second number is the number of elements in the array.
bool frog(int a, int b) {
return a > b;
}
What are the parameters for the function frog?
a and b
What is the library used for inputs/outputs?
iostream or #include <iostream>
What conditional statement it used when you have exhausted every other statement?
else statement
string fruits = {"orange", "banana", "apple", "cherry", "strawberry"};
for (int i=0; i<2; i++) {
for (int j=0; j<5; j++) {
cout << fruits[j][0] << " ";
}
cout << endl;
}
What is the output?
o b a c s
o b a c s
In a 2D array, how do I access the third element of the fourth array from the 2D array "names"?
names[3][2]
Given integers a and b, a function returns a>b. What is the data type of the output of this function?
boolean
What are the two ways we move onto the next line in C++?
"\n" and endl
int num = 15;
if (num < 20) {
cout << "The number is less than 20.";
}
else if (num < 16){
cout << "The number is less than 16."; }
What is the output here?
The number is less than 20
for (int j = 0; j < 5; j++) {
for (int z = 0; z < j; z++) {
cout << "*";
}
cout << endl;
}
*
**
***
****
In a 2D array called "step" of size NxN, how do we access the last element of the last array?
step[N - 1][N - 1]
What is the return type if I don't want to return anything?
void
What is the total amount of bits an integer, double, float can hold? (Add them up)
128
Write a complete C++ "if-else" statement to determine if a given integer variable "num" is positive, negative, or zero, and print the result accordingly.
If it's good it's good
int n, variable = 1;
std::cout << "Enter a positive integer: ";
std::cin >> n;
for (int i = 1; i <= n; i++) {
variable *= i;
}
What is this program doing?
Getting the factorial of n
int arr[] = {10, 20, 30, 40, 50};
int n = sizeof(arr) / 4;
int sum = 0;
for (int i = 0; i < n / 2; i++) {
sum += arr[i] * arr[n - 1 - i];
}
cout << sum;
What does this output?
1300
Explain the difference between function declaration and function definition.
Function declaration: When the function is first introduced (ex: int main() )
Function definition: When what the function does is written out in code