1/21
Flashcards covering the fundamentals of C++, the compilation and build process, program structure, variables, literals, and core data types.
How does an interpreted language differ from a compiled language like C++ in terms of execution?
An interpreter reads source code line by line while running and translates instructions on the fly. In contrast, C++ uses a compiler to translate the entire program into machine code (binary) all at once before running, producing a standalone executable file that runs directly on hardware.
What are the three distinct steps in the C++ build process?
The three steps are preprocessing, compilation, and linking.
What is the role of the preprocessor in the C++ compilation model?
The preprocessor executes before compilation and handles directives starting with # (such as #include). It copies file contents, replaces shortcuts, and removes unnecessary parts to produce a single, complete file for the compiler.
What intermediate file is produced during the compilation step of C++, and what does it contain?
The compiler produces an object file (typically ending in .o or .obj), which contains translated machine code but is not yet a complete executable program.
What role does the linker play in the C++ build process?
The linker combines all compiled object files and external libraries into a single executable, resolving references so calls to functions defined in other files can be located.
What is the difference between header files and source files in C++?
Header files (.h or .hpp) define interfaces by declaring which functions and types exist without full implementations. Source files (.cpp) contain the actual implementation logic.
Why does C++ separate declarations into header files and implementations into source files?
Separating declarations and implementations allows files to be compiled independently and linked later, speeding up build times for large projects.
What is the purpose of the line #include
It allows the program to use standard input and output features, such as printing text to the screen using std::cout.
What role does int main() serve in a C++ program?
It defines the starting point or entry point where program execution always begins.
What does the prefix std:: indicate in C++?
The std:: prefix indicates that an identifier belongs to the C++ Standard Library namespace.
What function does std::endl perform when outputting text?
It ends the current line of output and moves the cursor to the next line.
What three essential attributes define a variable in C++?
Name (a unique identifier), Type (defines the kind of data stored and memory space occupied), and Value (the actual data held in memory).
What is the difference between variable declaration and variable initialisation in C++?
Declaration tells the compiler to reserve memory space for a variable of a specific type. Initialisation assigns a value to the variable at the exact moment it is created.
What are the typical memory sizes on modern systems for the integer types short, int, long, and long long?
short typically occupies 2bytes, int occupies 4bytes, long occupies 4or 8bytes (depending on the system), and long long occupies 8bytes.
How does using the unsigned keyword alter an integer variable in C++?
It restricts the variable to non-negative numbers only, effectively doubling its positive range. If a negative value is assigned, it wraps around to a large positive value.
Why does modern C++ provide fixed-width integers such as int32_t and int64_t from the
Because core integer sizes can vary across different computer systems, fixed-width integers guarantee exact sizes of 32bits and 64bits, respectively.
What are the three floating-point types in C++ and their typical precisions?
float (single precision, usually 32bits), double (double precision, usually 64bits, the default choice for decimals), and long double (extended precision, typically ≥64bits).
How does a computer internally store a C++ char variable?
The computer stores it as a number representing that character, usually based on the ASCII encoding system.
What numerical values do boolean variables output by default when printed to the console in C++?
true outputs as 1 and false outputs as 0.
What is an enumeration (enum) in C++, and what default integer value is assigned to the first enumerator?
An enumeration defines a custom type composed of named integer constants, where the first enumerator is assigned a value of 0 by default.
What is the purpose of the void type in C++, and why can variables not be created with it?
void indicates the absence of a value (commonly used for functions that return nothing). Variables of type void cannot be created because there is no data to store.
What four derived types in C++ are built upon fundamental data types?
Arrays (fixed-size sequences of elements), pointers (variables holding memory addresses), references (aliases to existing objects), and function types (methods with specified parameters and return values).