C++ deck Flashcards

1
Q

How to execute code in C++

A

You have to call the function main()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When does the program stop running?

A

When the function returns a value, the program stops executing, it starts executing at the line of main()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the meaning of a function?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True or false: the main function MUST return an integer

A

True, as it is named int main()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is static type checking?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are all the data types in C++?

A

char, boolean, int, double, float, long (know what the difference between each data type is completely I don’t really understand that)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to check the size of the data type?

A

You use the size function and the name of the data type

Ex: sizeof(int);, sizeof(long);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Expression statement

A

A single expression followed by a semicolon

Ex: a = 3; a + b;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Compound statement

A

A group of statements surrounded by brackets and are executed in order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Different control structures

A

if (variable > somevalue){
//this code will execute in order
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

switch statement

A

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
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the different loops?

A

while, do while, and for.
while(value < somevalue){
// statements
}

do{
// statements
} while(x < value);

for (int i = 0; i < 5; ++i){
// statements
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

GO BACK TO INTRO TO C++ SLIDES

A

YES

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Namespace

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How are strings defined in C?

A

They are defined through the use of arrays, for example char a[] = “abcd”; or car c[50] = “bcdf” (specifices the length of the char)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s the difference in C++(compared to C)

A

A string is defined by doing #include <string> as one of the preprocessor directives(because it accesses std:string) and then defining the variable ex:</string>

string variableName = “hello”;

17
Q

how would you compare strings?

A

You would just do if (variableName == variableName){
return value;
}

18
Q
A
19
Q
A