Lecture 2: C++ Basics Flashcards

1
Q

To use functions and objects in libraries, we must

A

Include them in our code and by doing this with an include directive at the top of our file.
Ex:
#include <iostream></iostream>

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

A namespace is

A

A collection of names (such as cin and cout)

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

An object named cout exists in the std (or standard) namespace. It might also exist in other namespaces, we instruct C++ to use the

A

Cout from the std namespace. Example of:
using namespace std;

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

When runs a program, executions always begins at the

A

Main function

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

The return 0 at the end of our main function tells to

A

End the program here
Ex:
cout &laquo_space;“Hello World”;
return 0;

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

Use a comment to write something in the program that the compiler will

A

Ignore

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

We can also place a comment on the same line as a statement. This is referred to as an

A

Incline comment

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

To create a multi-line comment, we can also use the following technique:

A

/Print “Hellow World” to the screen
These lines are ignored by the compiler
End of comment /

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

A variable can hold data of

A

A specific type and for now, we will only use variables that hold numbers

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

When we declare a variable, we tells to set aside a location in

A

Main memory large enough to hold a value of the given type

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

The declaration statement tells to:

A

1) Set aside a location in memory large enough to hold an integer
2) Given that memory location the name

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

Can place a value in or retrieve a value from a variable’s memory location by using its

A

Name

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

This code declares three variables. When they are created, they are each assigned a different

A

Memory address

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

The addresses assigned might be different each time the program runs. It depends on

A

What memory is free at the moment

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

Only need to use a variable’s name to access its

A

Memory address

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

The name of a variable is also called an

A

Identifier

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

Each identifier’s name must be unique in its

A

Scope (more on scope later) and the program only have one scope, so all identifier must be unique

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

C++ is a

A

Case sensitive language and this means the difference between uppercase and lowercase letters matters

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

A keyword or reserved word is

A

A special type of identifier
Ex: int, double, void, bool, for, while

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

Naming conventions - if a variable name is one word, it is written in lowercase

A

Ex: int number;

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

If a variable name has more than one word, it is written in

A

Camelcase
Ex: int numberOfBars

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

Since an identifier cannot have spaces, all words must be combined into

A

One word

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

Assignment statement

A

Ex: totalWeight = 5;

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

An assignment statement uses the “ = “ operator, also known as the

A

Assignment operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Unlike in math, " = " does not assert that its left and right operands are
Equal, rather it takes the value on the right and assigns it to a variable on the left
26
An expression is a series of
Values and operators that evaluates to a single value
27
When an expression is the right operand of " = ", it is
Evaluated first
28
When a variable appears to the LEFT of " = ", we are referring to its
Memory location
29
When a variable appears to the LEFT of " = ", we are referring to
The value stored at its memory location
30
An uninitialized variable has
Garbage data
31
To avoid uninitialized variables, we can give them a value on the same line that we
Declare them Ex: int miniNumber = 3;
32
An input stream is a stream of
Input being entered into the computer for our program to use
33
The programs as we write this course will receive this input comes from
The keyboard
34
An output stream is a stream of
Output generated by our program and given to the user
35
The program we write in this course will display their output in
A console window on the user's monitor
36
cout << ""; is used to
Display information to the screen
37
Recall that to use it, we must include, what?
iostream in our program
38
cout << ""; is short for
Console output
39
<< is called the
Arrow symbol or stream insertion operator
40
<<, the stream insertion oeprator sends the value of
its right operand to its left operand (cout) then cout will print the value to the screen
41
You can think of << as an arrow pointing the data to be printed to
Cout
42
Escape sequence
The backslash and the following character are referred to when a backflash appears before a character in a string, we are telling the compiler to not actually include that letter in the string
43
Using "cin" for input is similar to using
Cout for output
44
Two arrows pointing to the right are the
Extraction operator ">>"
45
"cin" receives keyboard input from the user and places it in a
Pre-declared variable
46
Note: It must be declared but does not need to be
Initialized Ex: int number; // 'number is correctly pre-declared' cin >> number;
47
When an extraction operator statement is
Reached, program execution pauses
48
Since program execution pauses when an extraction operator is
Reached, it is important to always display a prompt before reading input to cin
49
A prompt is text asking the user to
Enter input (and telling them what that input should be)
50
51
It is possible to retrieve values for more than one variable with
A single "cin" statement Ex: int price, amount; cout << "Enter the price and amount: "; cin >> price >> amount;
52
Keyboard buffer
The character and the user types are stored in a section of memory
53
#include and note that we also need to add
using namespace std if we have not already
54
Once the string library is included in our program, we can declare variable of type string as we would
Any other data type Ex: string day; day = "Monday";
55
The right operand of the assignment operator is a
String literal
56
A string literal is
Text placed inside quotation marks
57
It is called literal because
It is not a variable value. Rather the letters inside the quotes are the literal string being assigned to the left operand.
58
The "+" operator performs a different operation if its two operands are
String rather than numeric values are known "string concatenation"
59
As with numeric and character values, it is possible to use the >> operator with
"cin" to input a "string" from the keyboard
60
"cin" ignores leading whitespace characters, so it is
Continue reading from the buffer
61
When "cin" reaches the first non-leading whitespace character in the buffer, it stops
Reading and sends the characters that have been read to name
62
Everything that has been read is cleared from
The buffer
63
When this statement is reached, the keyboard buffer is
Not empty and executions does not pause and cin reads the first character in the buffer