Block
List of statements enclosed in curly brackets
What is the difference between a while and a do-while loop?
A Do-While loop will run the statement once then check for correct iteration, a While loop will only check for correct iteration
For-Loop
A loop that tracks the amount of iterations the loop execute
Init Statement
Initialization statement, first statement executed in a loop
Loop Variable
Variable declared inside for, declared inside of loop and scope is inside body of loop
Break
Exits the innermost loop
Continue
Skips the remaining statements and start new iteration
Iterate and Keep Track Idiom
Declare variable before loop and output variable after loop to see result
Nested Iterative Construct
One iterative construct inside of another, may be more than two loops deep, all loops can be nested together, loop body may contain other code
Function
Named group of statements carrying out a particular task that accepts values and computes the result
Function Name
Identifier distinguishing the function from others
Argument
The value accepted by the function to use in computation
Return Value
Value computed by the function
Function Call/Function Invocation
Executing function code from elsewhere in program
Nested Function Call
Use of one function call as argument to another
In expression Function Invocation
Return value replaces invocation in expression evaluation
Example of in expression function invocation
result = sqrt(9.0 - myVar * 5)
Standalone Function Invocation
Return value is ignored
Example of Standalone Function Invocation
srand(55);
Predefined Function
Libraries of code that can be reused in programs
Function may have more than one argument
result = pow(myVar, 55);
An argument is an arbitrary expression
result = sqrt(myVar * 2 + 9.0);
How is an include directive related to predefined functions?
Specific include directives must be used to use certain predefined functions
Include Directive
Libraries that are already in the C++ language
What are type changing functions and why are they needed?
Functions that can change the type of a variable for a specific situation. Needed to correctly operate between variables of different types
Type Casting
Explicit type conversion
Example of Type Casting
double c=static_cast<double>(a)/b;
Type Coercion
Implicit type conversion
Example of Type Coercion
double c = a + 30;
time(nullptr)
Returns number of seconds since 01/01/1970, good for initializing unique series, needs <ctime>
rand()
Returns a new integer random number in the series, can be used multiple times in a program, no argument
srand()
Initializes random number generator, needs to be invoked once in the program, no return value
Seed
Integer, selects the pseudo random series
RAND_MAX
The maximum a random number can go up to
Ranged Number Idiom
Take a remainder of that range
Example of Ranged Number Idiom
Random number between 0 and 9:
int myRandValue = rand() % 10;
Function
Named collection of statements that can be called later in the program
Predefined Function
Libraries of code that can be called in programs through an include directive
Programmer-Defined Function
Function that the programmer creates to call later in the program
Argument
The value accepted by the function to use in a computation
Parameter
Local variables of the callee that are initialized to the value of arguments at invocation
Return Value
Value computed by the function
Function Call/Function Invocation
Executing function code from elsewhere in program
Caller
Function that invokes another
Callee
Function that is being invoked
Function Definition
Specifies instructions that the function executes
Head
returnType functionName (parameter)
Body
Includes collection of statements and return statement
Function Prototype
Declares the function
Function Prototype Expanded Form
Mentions parameter types and names: names are optional but sometimes desirable for clarity EX: int add1 (int i);
Function Prototype Abbreviated Form
Mentions only parameter type EX: int add1 (int);
Local Variable
Variable that can only be used inside a specific block
Global Constant
A constant declared outside any function definition
Scope
Area in which a variable can be used
Call-By-Value
Changing the value of the parameters ( does not affect values of the original arguments)
Executable Statement
Machine code is generated by the compiler. EX: assignment statement, looping/branching constructs, function invocation
Non-executable Statement
No machine code generated. EX function prototypes, variable and constant declaration, #include directives
header file
A file that is found in the same directory as the rest of the code. Called on with #include "filename.h
How is a header file different from an include file?
they are actually the same
What is the difference between include <filename> and #include "filename.h
include "filename.h" calls a file that is in the same directory as your code while #include <filename> is found in a standard system-dependent
Why are programs included in multiple files?
It makes the program easier to maintain and allows the programs to be compiled separately
Object File
Unlinked machine code files from source code
How are object files related to a multiple-file program?
The source program and include files are compiled into an object file
Linking
Turning an object file into executable code
How are multi-file programs linked?
#include "filename.fileExtention
Multiple Inclusion Protection
Structuring a header file in case of multiple inclusion of a specific file
Void Function
A function that does not return a value, can only be used as a standalone statement, Void is specified as return type
No
Can a Void Function be invoked as an expression?
Predicate
Function whose return value is boolean
How can a Predicate be used?
As an expression in a looping or branching construct
Program Stack
Means of RAM allocation for local function variables
Function Frame
Unit of call stack allocation
Active Frame
Frame of currently executing function
Call-By-Value
Passing arguments to a function copies the actual value of an argument into the formal parameter of the function
Call-By-Reference
Parameter passing discipline that allows the function to modify the arguments, it assigns parameter the same memory location as argument, affects the argument
How are Call-By-Value and Call-By-Reference different syntactically?
Call-By-Reference has an & before the identifiers of the parameters
No
Can an expression be passed by reference?
Block
List of statements enclosed in curly brackets
What is the difference between a while and a do-while loop?
A Do-While loop will run the statement once then check for correct iteration, a While loop will only check for correct iteration
For-Loop
A loop that tracks the amount of iterations the loop execute
Init Statement
Initialization statement, first statement executed in a loop
Loop Variable
Variable declared inside for, declared inside of loop and scope is inside body of loop
Break
Exits the innermost loop
Continue
Skips the remaining statements and start new iteration
Iterate and Keep Track Idiom
Declare variable before loop and output variable after loop to see result
Nested Iterative Construct
One iterative construct inside of another, may be more than two loops deep, all loops can be nested together, loop body may contain other code
Function
Named group of statements carrying out a particular task that accepts values and computes the result
Function Name
Identifier distinguishing the function from others
Argument
The value accepted by the function to use in computation
Return Value
Value computed by the function
Function Call/Function Invocation
Executing function code from elsewhere in program
Nested Function Call
Use of one function call as argument to another
In expression Function Invocation
Return value replaces invocation in expression evaluation
Example of in expression function invocation
result = sqrt(9.0 - myVar * 5)
Standalone Function Invocation
Return value is ignored
Example of Standalone Function Invocation
srand(55);
Predefined Function
Libraries of code that can be reused in programs
Function may have more than one argument
result = pow(myVar, 55);
An argument is an arbitrary expression
result = sqrt(myVar * 2 + 9.0);
How is an include directive related to predefined functions?
Specific include directives must be used to use certain predefined functions
Include Directive
Libraries that are already in the C++ language
What are type changing functions and why are they needed?
Functions that can change the type of a variable for a specific situation. Needed to correctly operate between variables of different types
Type Casting
Explicit type conversion
Example of Type Casting
double c=static_cast<double>(a)/b;
Type Coercion
Implicit type conversion
Example of Type Coercion
double c = a + 30;
time(nullptr)
Returns number of seconds since 01/01/1970, good for initializing unique series, needs <ctime>
rand()
Returns a new integer random number in the series, can be used multiple times in a program, no argument
srand()
Initializes random number generator, needs to be invoked once in the program, no return value
Seed
Integer, selects the pseudo random series
RAND_MAX
The maximum a random number can go up to
Ranged Number Idiom
Take a remainder of that range
Example of Ranged Number Idiom
Random number between 0 and 9:
int myRandValue = rand() % 10;
Function
Named collection of statements that can be called later in the program
Predefined Function
Libraries of code that can be called in programs through an include directive
Programmer-Defined Function
Function that the programmer creates to call later in the program
Argument
The value accepted by the function to use in a computation
Parameter
Local variables of the callee that are initialized to the value of arguments at invocation
Return Value
Value computed by the function
Function Call/Function Invocation
Executing function code from elsewhere in program
Caller
Function that invokes another
Callee
Function that is being invoked
Function Definition
Specifies instructions that the function executes
Head
returnType functionName (parameter)
Body
Includes collection of statements and return statement
Function Prototype
Declares the function
Function Prototype Expanded Form
Mentions parameter types and names: names are optional but sometimes desirable for clarity EX: int add1 (int i);
Function Prototype Abbreviated Form
Mentions only parameter type EX: int add1 (int);
Local Variable
Variable that can only be used inside a specific block
Global Constant
A constant declared outside any function definition
Scope
Area in which a variable can be used
Call-By-Value
Changing the value of the parameters ( does not affect values of the original arguments)
Executable Statement
Machine code is generated by the compiler. EX: assignment statement, looping/branching constructs, function invocation
Non-executable Statement
No machine code generated. EX function prototypes, variable and constant declaration, #include directives
header file
A file that is found in the same directory as the rest of the code. Called on with #include "filename.h
How is a header file different from an include file?
they are actually the same
What is the difference between include <filename> and #include "filename.h
include "filename.h" calls a file that is in the same directory as your code while #include <filename> is found in a standard system-dependent
Why are programs included in multiple files?
It makes the program easier to maintain and allows the programs to be compiled separately
Object File
Unlinked machine code files from source code
How are object files related to a multiple-file program?
The source program and include files are compiled into an object file
Linking
Turning an object file into executable code
How are multi-file programs linked?
#include "filename.fileExtention
Multiple Inclusion Protection
Structuring a header file in case of multiple inclusion of a specific file
Void Function
A function that does not return a value, can only be used as a standalone statement, Void is specified as return type
No
Can a Void Function be invoked as an expression?
Predicate
Function whose return value is boolean
How can a Predicate be used?
As an expression in a looping or branching construct
Program Stack
Means of RAM allocation for local function variables
Function Frame
Unit of call stack allocation
Active Frame
Frame of currently executing function
Call-By-Value
Passing arguments to a function copies the actual value of an argument into the formal parameter of the function
Call-By-Reference
Parameter passing discipline that allows the function to modify the arguments, it assigns parameter the same memory location as argument, affects the argument
How are Call-By-Value and Call-By-Reference different syntactically?
Call-By-Reference has an & before the identifiers of the parameters
No
Can an expression be passed by reference?