Chapter 1 Flashcards

Important information to know from Chapter 1

1
Q

What is a compiler?

A

A compiler is a program that translates source code written in a programming language (like C++) into machine code that can be executed by a computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the #include directive commonly used for in C++?

A

This is commonly used to include standard library header files or user-defined header files in your program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of the compiler?

A

The purpose of a compiler is to transform human-readable code into a format that a computer can understand and execute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of the #include directive?

A

The #include directive in C++ tells the preprocessor to insert the contents of another file into the source code at the point where the directive is found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does a .cpp suffix at the end of a file name signify in C++?

A

A file with a .cpp suffix is a C++ source file. This file contains the source code written in the C++ programming language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the linker do for your program?

A

After the compiler creates object files from the source code, the linker combines these object files into a single executable program. The linker also resolves any symbolic references to memory locations, such as function calls or variables that are defined in different source files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between a source file and an object file?

A

A source file (like a .cpp file) contains the source code written by the programmer.

An object file is a file containing object code, including instructions that the computer can understand directly (machine code), but that is not ready to be run as a program.

It’s an intermediate file produced by the compiler after it processes a source file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an executable?

A

An executable is a file that contains a program - that is, a particular kind of file that is capable of being executed or run as a program in the computer.

In simple terms, it’s the final output of the compilation and linking process that you can run on your computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a comment?

A

A comment is a programmer-readable explanation or annotation in the source code. It is completely ignored by compilers and interpreters.

In C++, comments can be single-line, starting with //, or multi-line, enclosed by /* and */.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the four parts of a function in C++?

A
  • A return type
  • A name
  • A parameter list, enclosed in parentheses
  • A function body, enclosed in a set of “curly braces”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the purpose behind ending he function main

A

To tell the C++ program where to start executing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a function?

A

A named sequence of instructions for the computer to execute in the order in which they are written

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an error?

A

A mistake made in your code resulting in it not working properly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the command line?

A

A text-based editing environment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is object code?

A

A machine-readable version of code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a header file?

A

A file that store predefined functions

15
Q

What is compile-time?

A

The time at which source code is converted into an executable code

16
Q

What is a module?

A

A module is a set of source code files that are compiled independently of the source files (or more precisely, the translation units that import them.)

17
Q

What is a translation unit?

A

It is the ultimate input to a C or C++ compiler from which an object file is generated.

18
Q

What does a translation unit consist of?

A

It roughly consists of:
- a source file after it has been processed by the C preprocessor, meaning that header files listed in #include directives are literally included,
- sections of code within #ifndef may be included,
- and macros have been expanded.

19
Q

How do modules reduce many of the problems associated with header files?

A
  • They often reduce compilation times, sometimes significantly.
    -Macros, preprocessor directives, and nonexported names declared in a module aren’t visible outside the module. They have no effect on the compilation of the translation unit that imports the module.
  • You can import modules in any order without concern for macro redefinitions. - Declarations in the importing translation unit don’t participate in overload resolution or name lookup in the imported module.
  • After a module is compiled once, the results are stored in a binary file that describes all the exported types, functions, and templates. The compiler can process that file much faster than a header file. And, the compiler can reuse it every place where the module is imported in a project.
20
Q

How can you use modules side by side with header files?

A

A C++ source file can import modules and also #include header files.

21
Q

What is the difference between an imported header and an imported module?

A

The main difference between an imported header and an imported module is that any preprocessor definitions in the header are visible in the importing program immediately after the import statement.

22
Q

What is debugging?

A

Fixing mistakes made in your program

23
Q

What does cout do in C++?

A

cout is used to display output to the screen.

24
Q

What is std?

A

The std is a short form of standard, the std namespace contains the built-in classes and declared functions.

25
Q

What is main()?

A

Main() is the main function, everytime your program gets executed, the main() function is called. You can call other functions too, but you have to call them inside the main().