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
Q

Unlike in math, “ = “ does not assert that its left and right operands are

A

Equal, rather it takes the value on the right and assigns it to a variable on the left

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

An expression is a series of

A

Values and operators that evaluates to a single value

27
Q

When an expression is the right operand of “ = “, it is

A

Evaluated first

28
Q

When a variable appears to the LEFT of “ = “, we are referring to its

A

Memory location

29
Q

When a variable appears to the LEFT of “ = “, we are referring to

A

The value stored at its memory location

30
Q

An uninitialized variable has

A

Garbage data

31
Q

To avoid uninitialized variables, we can give them a value on the same line that we

A

Declare them
Ex: int miniNumber = 3;

32
Q

An input stream is a stream of

A

Input being entered into the computer for our program to use

33
Q

The programs as we write this course will receive this input comes from

A

The keyboard

34
Q

An output stream is a stream of

A

Output generated by our program and given to the user

35
Q

The program we write in this course will display their output in

A

A console window on the user’s monitor

36
Q

cout &laquo_space;””; is used to

A

Display information to the screen

37
Q

Recall that to use it, we must include, what?

A

iostream in our program

38
Q

cout &laquo_space;””; is short for

A

Console output

39
Q

&laquo_space;is called the

A

Arrow symbol or stream insertion operator

40
Q

«, the stream insertion oeprator sends the value of

A

its right operand to its left operand (cout) then cout will print the value to the screen

41
Q

You can think of &laquo_space;as an arrow pointing the data to be printed to

A

Cout

42
Q

Escape sequence

A

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
Q

Using “cin” for input is similar to using

A

Cout for output

44
Q

Two arrows pointing to the right are the

A

Extraction operator “»”

45
Q

“cin” receives keyboard input from the user and places it in a

A

Pre-declared variable

46
Q

Note: It must be declared but does not need to be

A

Initialized
Ex:
int number; // ‘number is correctly pre-declared’
cin&raquo_space; number;

47
Q

When an extraction operator statement is

A

Reached, program execution pauses

48
Q

Since program execution pauses when an extraction operator is

A

Reached, it is important to always display a prompt before reading input to cin

49
Q

A prompt is text asking the user to

A

Enter input (and telling them what that input should be)

50
Q
A
51
Q

It is possible to retrieve values for more than one variable with

A

A single “cin” statement
Ex:
int price, amount;
cout &laquo_space;“Enter the price and amount: “;
cin&raquo_space; price&raquo_space; amount;

52
Q

Keyboard buffer

A

The character and the user types are stored in a section of memory

53
Q

include <string> and note that we also need to add</string>

A

using namespace std if we have not already

54
Q

Once the string library is included in our program, we can declare variable of type string as we would

A

Any other data type
Ex:
string day;
day = “Monday”;

55
Q

The right operand of the assignment operator is a

A

String literal

56
Q

A string literal is

A

Text placed inside quotation marks

57
Q

It is called literal because

A

It is not a variable value. Rather the letters inside the quotes are the literal string being assigned to the left operand.

58
Q

The “+” operator performs a different operation if its two operands are

A

String rather than numeric values are known “string concatenation”

59
Q

As with numeric and character values, it is possible to use the&raquo_space; operator with

A

“cin” to input a “string” from the keyboard

60
Q

“cin” ignores leading whitespace characters, so it is

A

Continue reading from the buffer

61
Q

When “cin” reaches the first non-leading whitespace character in the buffer, it stops

A

Reading and sends the characters that have been read to name

62
Q

Everything that has been read is cleared from

A

The buffer

63
Q

When this statement is reached, the keyboard buffer is

A

Not empty and executions does not pause and cin reads the first character in the buffer