Introduction to C++ and its Compilation Model

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/21

flashcard set

Earn XP

Description and Tags

Flashcards covering the fundamentals of C++, the compilation and build process, program structure, variables, literals, and core data types.

22 Terms

1
New cards

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.

2
New cards

What are the three distinct steps in the C++ build process?

The three steps are preprocessing, compilation, and linking.

3
New cards

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.

4
New cards

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.o or .obj.obj), which contains translated machine code but is not yet a complete executable program.

5
New cards

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.

6
New cards

What is the difference between header files and source files in C++?

Header files (.h.h or .hpp.hpp) define interfaces by declaring which functions and types exist without full implementations. Source files (.cpp.cpp) contain the actual implementation logic.

7
New cards

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.

8
New cards

What is the purpose of the line #include in a basic C++ program?

It allows the program to use standard input and output features, such as printing text to the screen using std::coutstd::cout.

9
New cards

What role does int main()int\ main() serve in a C++ program?

It defines the starting point or entry point where program execution always begins.

10
New cards

What does the prefix std::std:: indicate in C++?

The std::std:: prefix indicates that an identifier belongs to the C++ Standard Library namespace.

11
New cards

What function does std::endlstd::endl perform when outputting text?

It ends the current line of output and moves the cursor to the next line.

12
New cards

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).

13
New cards

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.

14
New cards

What are the typical memory sizes on modern systems for the integer types short, int, long, and long long?

short typically occupies 2 bytes2\,\text{bytes}, int occupies 4 bytes4\,\text{bytes}, long occupies 4 or 8 bytes4\,\text{or }8\,\text{bytes} (depending on the system), and long long occupies 8 bytes8\,\text{bytes}.

15
New cards

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.

16
New cards

Why does modern C++ provide fixed-width integers such as int32_t and int64_t from the header?

Because core integer sizes can vary across different computer systems, fixed-width integers guarantee exact sizes of 32 bits32\,\text{bits} and 64 bits64\,\text{bits}, respectively.

17
New cards

What are the three floating-point types in C++ and their typical precisions?

float (single precision, usually 32 bits32\,\text{bits}), double (double precision, usually 64 bits64\,\text{bits}, the default choice for decimals), and long double (extended precision, typically ≥64 bits\ge 64\,\text{bits}).

18
New cards

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.

19
New cards

What numerical values do boolean variables output by default when printed to the console in C++?

true outputs as 11 and false outputs as 00.

20
New cards

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 00 by default.

21
New cards

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.

22
New cards

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).