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
How to include the IO library?
#include
26
What is the std::cout variables? what does "cout" stand for
It allows you to send data to the console to be printed as text. character output
27
How do you send to the console with the std::count variable?
you use the insertion operator (
28
What is the std::endl?
THis prints a newline character to console
29
Why do people use \n over std:endl?
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
30
How to use '\n'
You have to use single quotes when used by itself. Otherwise use it naturally
31
What is std::cin
It reads input from keyboard using the extraction operator (>>). Input must be stored in a variable
32
What is uninitialized variables?
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
33
What is undefined behavior?
When using the value from an uninitialized variable. When you execute code whose behavior is not well defined
34
What is whitespace?
Refers to characters that are used for formatting purposes (spaces, tabs, newlines)
35
What are literals?
A literal is a fixed value that has been inserted directly into the source code
36
How is literal different from value(type)?
Value of an interval is fixed and can't be damage (constant)
37
What is an operation
Mathematical calculation involving zero/more input values (operands) that produces an new value
38
What are expressions
Combination of literals, variables, operators, and function calls that can be executed to produce a singular value.
39
What is evaluation and result in expressions?
Process of executing an expression is evaluation and the single value produced the result.
40
What is a user defined function
``` return-type identifier () { // your code } ```
41
Is nest functions supported in C++
No
42
What is return by value in functions?
Functions will use a return statement to indicated specific values to be returned to the caller. It sends the value.
43
What are void return values
They tell the compiler that the function does not return a value
44
What is the return value from | main function
It is called a status or exit code which terminates the program
45
What are function parameters
They are variables used in functions. Must be initialized with a value provided by the caller of the function
46
What are local variables?
Function parameters, as well as variables defined inside a function body
47
What is an identifier's scope?
Determines where the identifier can be accessed within the source code.
48
What is a forward declaration
It allows us to tell the compiler about the existence of an identifier before actually defining the identifier
49
What is a function prototype
Consists of a return type, name, and parameter, but no function body int add(int x, int y);
50
What is a definition?
A definition actually implements or instantiates the identifier.
51
What is a declaration?
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
What is a namespace?
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
What is the global namespace
Any name not defined inside a class, function, or a namespace
54
What is the scope resolution operator?
:: symbol | Left of symbol identifies the namespace that the name to the right is contained within
55
What a using directive
Tells compiler to check a specified namespace when trying to resolve an identifier that has no namespace prefix using namespace std;
56
What is the preprcoessor
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
What are preprocessor directives
Instructions that start with a #symbol and end with a newline not a semicolon
58
What do preprocessor directives do
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
What does includes do?
The #include directive makes the preprocessor replace the #include directive with the contents of the included file and then compiled
60
What is a macro?
Is a rule that defines how input text is converted into replacement output text.
61
What does this output #define MY_NAME "ALEX" ``` int main() { std::cout << "My name is: " << MY_NAME; return 0 } ```
My name is: Alex
62
What is conditional compilation
Allow you to specify under what conditions something will or won't compile ``` #ifdef #ifndef #endif ```
63
What does #ifdef preprocessor directive do?
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
What does #indef do
it is opposite of #ifdef and allow syou check if it was not defined
65
What does #if 0 do
Exclude this block of code from being compiled
66
What are header files?
.h extension on files Allows you to put declarations in one location and then import them wherever we need them
67
Angled brackets vs double quotes
Use double quotes to include header files included in current directory and angled brackets to include headers that come with your compiler
68
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?
transitive includes
69
LIST OF HEADER FILE BEST PRACTICES
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
How to create header guards
``` #ifndef SOMENAME #define SOMENAME ``` #endif
71
Whats a syntax error?
When you write a statement that is not valid according to the grammar of the c++ language
72
Whats a semantic error
Statment is syntactically valid, but does not do what the programmer intended
73
List the 5 steps to debugging a problem
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
Whats the first a most important step to finding the rpoblem
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
What is a binary digit (bit)
Smallest unit of memory 1 or 0
76
What is memory addresses
Memory organized into sequential units
77
What is a byte? how many bits?
Group of bits that are operated as a unit. 8 sequential bits.
78
What is a data type
Its used to tell the compiler how to interpret the contents of memory
79
An object with n bits can hold....
2^n
80
Minimum size of data types
``` boolean - 1 byte char - 1 byte short - 2 byte int - 2 byte long - 4 byte float - 4 bytes double - 8 bytes ```
81
How to determine the size of a data type
sizeof(data_type)
82
What is an integer
An integral type that can represent positive and negative whole numbers
83
What is signed integers
Number's sign is stored as part of the number (uses a single bit called the sign bit)
84
Whats the range of 8 bit signed?
-128 to 127
85
Whats range of 16 bit signed?
-32768 to 32767
86
What is integer overflow
When we try to store a value that is outside the range of the type
87
A n-bit unsigned variable has a range of
0 to (2^n) - 1
88
What behavior do unsigned numbers have with overflow?
It wraps around
89
Why isn't the size of the integer variables fixed?
So that compiler implementers could pick a size for int that performs best on the target computer architecture
90
Two downsides of fixed-width itntegers
Are not guaranteed to be defined on all architectures. also may be slower than a wider type on some archiectures
91
What are fast and least integers
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
What is std::size_t
An unsigned integral type, that typically is used to represent the size or length of objects
93
What are the digits in the part before the e in scientific notation?
Significant digits
94
What is the number of sigdigts do
defines a numbers precision
95
Whats a floating point type variable
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
Will std:cout print fractional part of a number
no
97
Whats the default precision of std::cout
6
98
How to override the default precision
``` #include //for output manipulator function std::setprecision(#) ```
99
What is rounding error
When precision is lost because a number can't be stored precisely
100
Two special categories of float
Inf - infinity | NaN - Not a number or IND
101
What do true and false evaluate to
1 and 0
102
how to get std::cout to print true or false instead of 1 and 0
std::boolalpha
103
What does cin accept inputs for boolean variables
0 and 1
104
What is a if statement?
Allows us to execute one or more lines of code only if some condition is true
105
what is a condition
an expression that evaluates to a boolean value
106
What is the char data type?
Designed to hold a character
107
How are char variables stored as
As an integer - ASCII character
108
What is ASCII code
Stands for american standard character for information interchange. Way to represent english characters as numbers 0 to 127
109
\n
start new line
110
\a
alert
111
\b
backspace
112
\t
horizontal tab
113
\v
vertical tab
114
\'
single quote
115
\"
double quote
116
Rule between single and double quotes
Put single chars in single quotes. Text put between double quotes
117
What is implicit type conversion
When compiler does type conversion for you automatically
118
Rule for implicit type conversions
int to double is safe | double to int is not safe
119
Perform a explicit type conversion
static_cast (expression) takes value from expression as input and returns a value converted into the type new_type
120
how to read a full line of input into a string
std::getline(std::cin >> std::ws, age)
121
What are literal constants
Unnamed values inserted directly into the code
122
What happens in floating point division
If either(or both) value is float then fraction is kept
123
What happens in integer division
It will divide by drop the fractional component
124
What happens when you do modulus with a negative number
The remainder will carry the sign