C+= Flashcards

1
Q

What does a C++ compiler do?

A

It sequentially goes through each source code (.cpp) file and does 1. check if code follows rules of C++ and 2. translates C++ source code into a machine language file called an object file (.o / .obj)

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

What does the linker do?

A
  1. Takes all object files generated by compiler and combine them into a single executable program (.exe)
  2. Capable of linking library files
  3. All cross-file dependencies are resolved properly
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a statement? Why are they the most common type of instruction?

A

A statement is a type of instruction that causes the program to perform some action.

They are the smallest independent unit of computation in the c++ lang.

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

What are Functions? What function must every program have?

A

Is a reusable sequence of statements designed to do a particular job.

The main function.

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

What is syntax error?

A

Is a compiler error that occurs at compile-time when your program violates grammar rules

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

What is the C++ Standard library?

A

A library file is collection of precompiled code that has been packaged up for reuse in other programs

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

What are programs?

A

Collections of instructions that manipulate data to produce a desired result

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

What is data and value

A

Data is any information that can be moved, processed, or stored by a computer. Value is a single piece of data stored in memeory.

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

What is a variable and identifier?

A

Variables is a named object while identifier is the name of the object.

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

What is an object?

A

Region of storage (usually memory) that has a value and other associated properties

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

How to create a variable

A

Use a special kind of declaration statement called a definition.

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

What is the use of RAM (random access memory)?

A

Its basically like a bunch of mailboxes that can be used to hold pieces of data while program is running

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

What is a data type? When must the type of a variable be known?

A

Tells program how to interpret a value in memory or what type of value the variable will store.

Must be known at compile-time

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

What happens at runtime when program runs?

A

The variable will be instantiated. Instantiation mean sobject will be created and assigned a memory address.

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

What is assignment?

A

Using the = assignment operator to give a variable a value after it has been defined

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

What is initialization?

A

When you provide an initial value for a variable at the same time it is defined

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

What is default initialization?

A

When no initialization value is provided

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

What is copy initialization

A

When value is provided after an equals sign

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

What is direct initialization

A

When value provided inside a parenthesis

int width(5);

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

What is brace initialization

A

int width {6};
int height = {6};
int depth {};

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

Why is brace initialization the best practice

A

Because it has a benefit to dishallowing narrowing conversions, meaning if you try to use brace to initialize a variable with a value it can not safely hold, the compiler will throw a warning or an error while the other init will truncate or round the number

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

What is value and zero initialization?

A

When a variable is initialized with empty braces, value init takes place and will init the variable to zero

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

What is best practice when initializing your variables?

A

Initialize upon creation

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

What is the input/output library?

A

Part of C++ standard library that deals with basic input/output (keyboard and console)

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

How to include the IO library?

A

include

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

What is the std::cout variables?

what does “cout” stand for

A

It allows you to send data to the console to be printed as text.

character output

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

How do you send to the console with the std::count variable?

A

you use the insertion operator (

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

What is the std::endl?

A

THis prints a newline character to console

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

Why do people use \n over std:endl?

A

The std::endl moves the cursor to the next line, and it flushes the output (makes sure that it shows up on screen immediately). THe std::cout already flushes already so it is not important. \n only moves cursor

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

How to use ‘\n’

A

You have to use single quotes when used by itself. Otherwise use it naturally

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

What is std::cin

A

It reads input from keyboard using the extraction operator (»). Input must be stored in a variable

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

What is uninitialized variables?

A

C/C++ does not initialize most variables to a given value (zero) auto. When a variable is assigned a memory location by the compiler, the default value of that variable is whatever value happens to already be in that memory

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

What is undefined behavior?

A

When using the value from an uninitialized variable. When you execute code whose behavior is not well defined

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

What is whitespace?

A

Refers to characters that are used for formatting purposes (spaces, tabs, newlines)

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

What are literals?

A

A literal is a fixed value that has been inserted directly into the source code

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

How is literal different from value(type)?

A

Value of an interval is fixed and can’t be damage (constant)

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

What is an operation

A

Mathematical calculation involving zero/more input values (operands) that produces an new value

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

What are expressions

A

Combination of literals, variables, operators, and function calls that can be executed to produce a singular value.

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

What is evaluation and result in expressions?

A

Process of executing an expression is evaluation and the single value produced the result.

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

What is a user defined function

A
return-type identifier () {
    // your code 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

Is nest functions supported in C++

A

No

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

What is return by value in functions?

A

Functions will use a return statement to indicated specific values to be returned to the caller. It sends the value.

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

What are void return values

A

They tell the compiler that the function does not return a value

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

What is the return value from

main function

A

It is called a status or exit code which terminates the program

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

What are function parameters

A

They are variables used in functions. Must be initialized with a value provided by the caller of the function

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

What are local variables?

A

Function parameters, as well as variables defined inside a function body

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

What is an identifier’s scope?

A

Determines where the identifier can be accessed within the source code.

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

What is a forward declaration

A

It allows us to tell the compiler about the existence of an identifier before actually defining the identifier

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

What is a function prototype

A

Consists of a return type, name, and parameter, but no function body

int add(int x, int y);

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

What is a definition?

A

A definition actually implements or instantiates the identifier.

51
Q

What is a declaration?

A

A statement that tells the compiler about the existence of an identifier and its type
A declaration is all a compiler needs to satisfy the compiler

52
Q

What is a namespace?

A

Region that allows you to declare names inside of it for the purpose of disambiguation. It provides a scope region to the names declared inside of it

53
Q

What is the global namespace

A

Any name not defined inside a class, function, or a namespace

54
Q

What is the scope resolution operator?

A

:: symbol

Left of symbol identifies the namespace that the name to the right is contained within

55
Q

What a using directive

A

Tells compiler to check a specified namespace when trying to resolve an identifier that has no namespace prefix

using namespace std;

56
Q

What is the preprcoessor

A

As a separate program that manipulates the text in each code file. It scans through the code file top to boottom, looking for preprocessor directives

57
Q

What are preprocessor directives

A

Instructions that start with a #symbol and end with a newline not a semicolon

58
Q

What do preprocessor directives do

A

Tell the preprocessor to perform specific particular text manipulation tasks. It does not understand C++ syntax. The output goes through several more translation phases and then is compiled

59
Q

What does includes do?

A

The #include directive makes the preprocessor replace the #include directive with the contents of the included file and then compiled

60
Q

What is a macro?

A

Is a rule that defines how input text is converted into replacement output text.

61
Q

define MY_NAME “ALEX”

What does this output

int main() {
 std::cout << "My name is: " << MY_NAME;
 return 0
}
A

My name is: Alex

62
Q

What is conditional compilation

A

Allow you to specify under what conditions something will or won’t compile

#ifdef
#ifndef
#endif
63
Q

What does #ifdef preprocessor directive do?

A

It allows the preprocessor to check whether an identifier has been previously #defined and if it was then it will compile whatever is contained inside #ifdef #endif

64
Q

What does #indef do

A

it is opposite of #ifdef and allow syou check if it was not defined

65
Q

if 0

What does

do

A

Exclude this block of code from being compiled

66
Q

What are header files?

A

.h extension on files

Allows you to put declarations in one location and then import them wherever we need them

67
Q

Angled brackets vs double quotes

A

Use double quotes to include header files included in current directory and angled brackets to include headers that come with your compiler

68
Q

What are additional header files that are implicitly included meaning when your code file includes the first header and then that header includes other header files?

A

transitive includes

69
Q

LIST OF HEADER FILE BEST PRACTICES

A

always include header guards
do not define variables/functions in header files
give header file the same name as the source file its associated with
each header file should have a specific job
be mindful of which headers you need explicitly include for the functionality tha tyou are using
every header you write should compile

70
Q

How to create header guards

A

endif

#ifndef SOMENAME
#define SOMENAME
71
Q

Whats a syntax error?

A

When you write a statement that is not valid according to the grammar of the c++ language

72
Q

Whats a semantic error

A

Statment is syntactically valid, but does not do what the programmer intended

73
Q

List the 5 steps to debugging a problem

A
  1. Find the root cause of the problem (line that breaks)
  2. Ensure you understand why issue is occuring
  3. Determine you to fix the issue
  4. Repair the issue
  5. retest to ensure problem is fixed and no new problems have emerged
74
Q

Whats the first a most important step to finding the rpoblem

A

Be able to reproduce teh problem 100% so that we can run the program over and over to look for clues and determine the issue

75
Q

What is a binary digit (bit)

A

Smallest unit of memory

1 or 0

76
Q

What is memory addresses

A

Memory organized into sequential units

77
Q

What is a byte? how many bits?

A

Group of bits that are operated as a unit. 8 sequential bits.

78
Q

What is a data type

A

Its used to tell the compiler how to interpret the contents of memory

79
Q

An object with n bits can hold….

A

2^n

80
Q

Minimum size of data types

A
boolean - 1 byte
char - 1 byte
short - 2 byte
int - 2 byte
long - 4 byte
float - 4 bytes
double - 8 bytes
81
Q

How to determine the size of a data type

A

sizeof(data_type)

82
Q

What is an integer

A

An integral type that can represent positive and negative whole numbers

83
Q

What is signed integers

A

Number’s sign is stored as part of the number (uses a single bit called the sign bit)

84
Q

Whats the range of 8 bit signed?

A

-128 to 127

85
Q

Whats range of 16 bit signed?

A

-32768 to 32767

86
Q

What is integer overflow

A

When we try to store a value that is outside the range of the type

87
Q

A n-bit unsigned variable has a range of

A

0 to (2^n) - 1

88
Q

What behavior do unsigned numbers have with overflow?

A

It wraps around

89
Q

Why isn’t the size of the integer variables fixed?

A

So that compiler implementers could pick a size for int that performs best on the target computer architecture

90
Q

Two downsides of fixed-width itntegers

A

Are not guaranteed to be defined on all architectures. also may be slower than a wider type on some archiectures

91
Q

What are fast and least integers

A

Fast types provide the fastest signed/unsigned integer type with a width atleast # bits

Least types provide the smallest signed/unsigned integer type with a width at least #bits

92
Q

What is std::size_t

A

An unsigned integral type, that typically is used to represent the size or length of objects

93
Q

What are the digits in the part before the e in scientific notation?

A

Significant digits

94
Q

What is the number of sigdigts do

A

defines a numbers precision

95
Q

Whats a floating point type variable

A

A variable that can hold a real number. It means decimal point can “float” and support a variable number of digits before and after the decimal point

96
Q

Will std:cout print fractional part of a number

A

no

97
Q

Whats the default precision of std::cout

A

6

98
Q

How to override the default precision

A
#include  //for output manipulator function
std::setprecision(#)
99
Q

What is rounding error

A

When precision is lost because a number can’t be stored precisely

100
Q

Two special categories of float

A

Inf - infinity

NaN - Not a number or IND

101
Q

What do true and false evaluate to

A

1 and 0

102
Q

how to get std::cout to print true or false instead of 1 and 0

A

std::boolalpha

103
Q

What does cin accept inputs for boolean variables

A

0 and 1

104
Q

What is a if statement?

A

Allows us to execute one or more lines of code only if some condition is true

105
Q

what is a condition

A

an expression that evaluates to a boolean value

106
Q

What is the char data type?

A

Designed to hold a character

107
Q

How are char variables stored as

A

As an integer - ASCII character

108
Q

What is ASCII code

A

Stands for american standard character for information interchange.

Way to represent english characters as numbers 0 to 127

109
Q

\n

A

start new line

110
Q

\a

A

alert

111
Q

\b

A

backspace

112
Q

\t

A

horizontal tab

113
Q

\v

A

vertical tab

114
Q

'

A

single quote

115
Q

"

A

double quote

116
Q

Rule between single and double quotes

A

Put single chars in single quotes. Text put between double quotes

117
Q

What is implicit type conversion

A

When compiler does type conversion for you automatically

118
Q

Rule for implicit type conversions

A

int to double is safe

double to int is not safe

119
Q

Perform a explicit type conversion

A

static_cast (expression)

takes value from expression as input and returns a value converted into the type new_type

120
Q

how to read a full line of input into a string

A

std::getline(std::cin&raquo_space; std::ws, age)

121
Q

What are literal constants

A

Unnamed values inserted directly into the code

122
Q

What happens in floating point division

A

If either(or both) value is float then fraction is kept

123
Q

What happens in integer division

A

It will divide by drop the fractional component

124
Q

What happens when you do modulus with a negative number

A

The remainder will carry the sign