learncpp.com – Flashcards

Unlock all answers in this set

Unlock answers
question
Statement
answer
The smallest independent unit in the language. (Sentence)
question
Declaration statement
answer
introduce new names into the current scope. These names can be: Type names (class, struct, union, enum, typedef, and pointer-to-member). Object names. Function names.
question
Expressions
answer
A combination of literals, variables, functions, and operators that evaluates to a value.
question
Functions
answer
A function is a collection of statements that executes sequentially.
question
Library
answer
A library is a collection of precompiled code (e.g. functions) that has been "packaged up" for reuse in many different programs.
question
Preprocessor directive
answer
Preprocessor directives tell the compiler to perform a special task.
question
Object
answer
An object is a piece of memory that can be used to store values.
question
Variable
answer
A variable in C++ is simply an object that has a name.
question
L-value
answer
An l-value is a value that has a persistent address (in memory). Since all variables have addresses, all variables are l-values.
question
R-value
answer
An r-value refers to values that are not associated with a persistent memory address. Examples of r-values are single numbers (such as 5, which evaluates to 5) and expressions (such as 2 + x, which evaluates to the value of variable x plus 2). r-values are generally temporary in nature and are discarded at the end of the statement in which they occur.
question
Initialization
answer
Define a variable AND give it an initial value in the same step.
question
Manipulators
answer
Manipulators are functions specifically designed to be used in conjunction with the insertion (<>) operators on stream objects
question
Buffer
answer
Buffer is a generic term that refers to a block of memory that serves as a temporary placeholder.
question
Namespaces
answer
Namespaces provide a method for preventing name conflicts in large projects.
question
Function
answer
A function is a reusable sequence of statements designed to do a particular job.
question
Identifier
answer
The name of a variable, function, type, or other kind of object in C++
question
Literal
answer
A fixed value that has been inserted (hardcoded) directly into the source code, such as 5, or 3.14159. Literals always evaluate to themselves.
question
Operands
answer
Literals, variables, and function calls that return values
question
Operators
answer
Tell the expression how to combine one or more operands to produce a new result.
question
Definition
answer
Implements or instantiates (causes memory to be allocated for) the identifier.
question
Declaration
answer
A statement that announces an identifier (variable or function name) and its type.
question
Directives
answer
Specific instructions that start with a # symbol and end with a newline
question
Signed
answer
Can hold both positive and negative values
question
Unsigned
answer
Can only hold positive values
question
Overflow
answer
occurs when bits are lost because a variable has not been allocated enough memory to store them.
question
Literal constants
answer
Values inserted directly into the code. They are constants because you can't change their values.
question
constexpr
answer
Ensures that the constant must be a compile-time constant
question
operator precedence
answer
The order in which operators are evaluated in a compound expression
question
Exponents in C++
answer
#include the header, and use the pow() function
question
unary operators
answer
operators that only take one operand
question
if (condition) expression; else other_expression;
answer
(condition) ? expression : other_expression;
question
Bitwise operators
answer
When evaluating bitwise OR, if any bit in a column is 1, the result for that column is 1. When evaluating bitwise AND, if all bits in a column are 1, the result for that column is 1. When evaluating bitwise XOR, if there are an odd number of 1 bits in a column, the result for that column is 1.
question
bit flags
answer
A flag is a predefined bit or bit sequence that holds a binary value
question
Block of statements "compound statements"
answer
A group of statements that is treated by the compiler as if it were a single statement.
question
global scope operator (::)
answer
Can be used to tell the compiler you mean the global version instead of the local version.
question
prefix global variable names
answer
"g_" to indicate that they are global
question
linkage
answer
Determines whether multiple instances of an identifier refer to the same variable or not.
question
A variable with internal linkage is called an internal variable
answer
Can be used anywhere within the file they are defined in, but can not be referenced outside the file they exist in.
question
A variable with external linkage is called an external variable
answer
Variables with external linkage can be used both in the file they are defined in, as well as in other files.
question
static keyword
answer
To make a global variable internal (able to be used only within a single file)
question
extern keyword
answer
to make a global variable external (able to be used anywhere in our program)
question
File scope vs. global scope
answer
Technically, in C++, all global variables in C++ have "file scope". However, informally, the term "file scope" is more often applied to file scope variables with internal linkage only, and "global scope" to file scope variables with external linkage.
question
static duration variable
answer
one that retains its value even after the scope in which it has been created has been exited
question
use "s_"
answer
to prefix static (static duration) variables.
question
What effect does using keyword "static" have on a global variable? What effect does it have on a local variable?
answer
When applied to a global variable, the static keyword defines the global variable as having internal linkage, meaning the variable cannot be exported to other files. When applied to a local variable, the static keyword defines the local variable as having static duration, meaning the variable will only be created once, and will not be destroyed until the end of the program.
question
automatic duration
answer
created at the point of definition, and destroyed when the block they are part of is exited.
question
static duration
answer
created when the program begins and destroyed when the program ends. This includes: Global variables Static local variables
question
dynamic duration
answer
are created and destroyed by programmer request. This includes: Dynamically allocated variables
question
Namespaces can be nested inside other namespaces
answer
we access g_x as Foo::Goo::g_x
question
implicit type conversion
answer
where the compiler automatically transforms one fundamental data type into another
question
explicit type conversions
answer
where the developer uses a casting operator to direct the conversion
question
numeric promotion (widening)
answer
Whenever a value from one type is converted into a value of a larger similar data type
question
Integral promotion
answer
involves the conversion of integer types narrower than int (which includes bool, char, unsigned char, signed char, unsigned short, signed short) to an integer (if possible) or an unsigned int.
question
Floating point promotion
answer
involves the conversion of a float to a double.
question
numeric conversion
answer
When we convert a value from a larger type to a similar smaller type, or between different types
question
cast
answer
represents an explicit request by the programmer to do a type
question
Rule: Avoid C-style casts
answer
Because C-style casts are not checked by the compiler at compile time, C-style casts can be inherently misused, because they will let you do things that may not make sense, such as getting rid of a const or changing a data type without changing the underlying representation (leading to garbage results).
question
What's the difference between implicit and explicit type conversion?
answer
Implicit type conversion happens when the compiler is expecting a value of one type but is given a value another type. Explicit type conversion happens when the user uses a type cast to convert a value from one type to another type.
question
the enum class (also called a scoped enumeration)
answer
makes enumerations both strongly typed and strongly scoped. To make an enum class, we use the keyword class after the enum keyword.
question
Typedef
answer
allow the programmer to create an alias for a data type, and use the aliased name instead of the actual type name. To declare a typedef, simply use the typedef keyword, followed by the type to alias, followed by the alias name
question
execution path
answer
The sequence of statements that the CPU executes
question
control flow statements
answer
allow the programmer to change the CPU's path through the program
question
null statement
answer
A statement with no body (just ;)
question
pseudo-random number generator (PRNG)
answer
is a program that takes a starting number (called a seed), and performs mathematical operations on it to transform it into some other number that appears to be unrelated to the seed.
question
robust
answer
A program that handles error cases well
question
buffer
answer
s simply a piece of memory set aside for storing data temporarily while it's moved from one place to another.
question
input validation
answer
The process of checking whether user input conforms to what the program is expecting
Get an explanation on any task
Get unstuck with the help of our AI assistant in seconds
New