C++ deck Flashcards
How to execute code in C++
You have to call the function main()
When does the program stop running?
When the function returns a value, the program stops executing, it starts executing at the line of main()
What is the meaning of a function?
A function is the start of the code that contains the return type(can be an int, double, or whatever) and the main function is the first function that is run or executes in a c++ file
True or false: the main function MUST return an integer
True, as it is named int main()
What is static type checking?
Checking to make sure that the variables and parameters are the data type that it is coded for before the main function runs(or before the program starts running) to identify errors.
What are all the data types in C++?
char, boolean, int, double, float, long (know what the difference between each data type is completely I don’t really understand that)
How to check the size of the data type?
You use the size function and the name of the data type
Ex: sizeof(int);, sizeof(long);
Expression statement
A single expression followed by a semicolon
Ex: a = 3; a + b;
Compound statement
A group of statements surrounded by brackets and are executed in order
Different control structures
if (variable > somevalue){
//this code will execute in order
}
switch statement
is kind of like an if sttaement, is formatted as
switch(value){
case 1:
//statements, 1 is compared with the value
break; (if you don’t have this, then the code will not stop running)
case 2:
// statements
default:
// this is when the value is not equal to 1 and 2
}
What are the different loops?
while, do while, and for.
while(value < somevalue){
// statements
}
do{
// statements
} while(x < value);
for (int i = 0; i < 5; ++i){
// statements
}
GO BACK TO INTRO TO C++ SLIDES
YES
Namespace
It’s like a container to put your functions and other things (like names and variables) and you can use that name of namespace to access those things
For example:
namespace first_space {
int add (int a, int b){
return a + b;
}
}
And then the way you would use these things in the main function is like this
int main(){
first_space::add(1, 2);
}
How are strings defined in C?
They are defined through the use of arrays, for example char a[] = “abcd”; or car c[50] = “bcdf” (specifices the length of the char)