C+= Flashcards
What does a C++ compiler do?
It sequentially goes through each source code (.cpp) file and does 1. check if code follows rules of C++ and 2. translates C++ source code into a machine language file called an object file (.o / .obj)
What does the linker do?
- Takes all object files generated by compiler and combine them into a single executable program (.exe)
- Capable of linking library files
- All cross-file dependencies are resolved properly
What is a statement? Why are they the most common type of instruction?
A statement is a type of instruction that causes the program to perform some action.
They are the smallest independent unit of computation in the c++ lang.
What are Functions? What function must every program have?
Is a reusable sequence of statements designed to do a particular job.
The main function.
What is syntax error?
Is a compiler error that occurs at compile-time when your program violates grammar rules
What is the C++ Standard library?
A library file is collection of precompiled code that has been packaged up for reuse in other programs
What are programs?
Collections of instructions that manipulate data to produce a desired result
What is data and value
Data is any information that can be moved, processed, or stored by a computer. Value is a single piece of data stored in memeory.
What is a variable and identifier?
Variables is a named object while identifier is the name of the object.
What is an object?
Region of storage (usually memory) that has a value and other associated properties
How to create a variable
Use a special kind of declaration statement called a definition.
What is the use of RAM (random access memory)?
Its basically like a bunch of mailboxes that can be used to hold pieces of data while program is running
What is a data type? When must the type of a variable be known?
Tells program how to interpret a value in memory or what type of value the variable will store.
Must be known at compile-time
What happens at runtime when program runs?
The variable will be instantiated. Instantiation mean sobject will be created and assigned a memory address.
What is assignment?
Using the = assignment operator to give a variable a value after it has been defined
What is initialization?
When you provide an initial value for a variable at the same time it is defined
What is default initialization?
When no initialization value is provided
What is copy initialization
When value is provided after an equals sign
What is direct initialization
When value provided inside a parenthesis
int width(5);
What is brace initialization
int width {6};
int height = {6};
int depth {};
Why is brace initialization the best practice
Because it has a benefit to dishallowing narrowing conversions, meaning if you try to use brace to initialize a variable with a value it can not safely hold, the compiler will throw a warning or an error while the other init will truncate or round the number
What is value and zero initialization?
When a variable is initialized with empty braces, value init takes place and will init the variable to zero
What is best practice when initializing your variables?
Initialize upon creation
What is the input/output library?
Part of C++ standard library that deals with basic input/output (keyboard and console)
How to include the IO library?
include
What is the std::cout variables?
what does “cout” stand for
It allows you to send data to the console to be printed as text.
character output
How do you send to the console with the std::count variable?
you use the insertion operator (
What is the std::endl?
THis prints a newline character to console
Why do people use \n over std:endl?
The std::endl moves the cursor to the next line, and it flushes the output (makes sure that it shows up on screen immediately). THe std::cout already flushes already so it is not important. \n only moves cursor
How to use ‘\n’
You have to use single quotes when used by itself. Otherwise use it naturally
What is std::cin
It reads input from keyboard using the extraction operator (»). Input must be stored in a variable
What is uninitialized variables?
C/C++ does not initialize most variables to a given value (zero) auto. When a variable is assigned a memory location by the compiler, the default value of that variable is whatever value happens to already be in that memory
What is undefined behavior?
When using the value from an uninitialized variable. When you execute code whose behavior is not well defined
What is whitespace?
Refers to characters that are used for formatting purposes (spaces, tabs, newlines)
What are literals?
A literal is a fixed value that has been inserted directly into the source code
How is literal different from value(type)?
Value of an interval is fixed and can’t be damage (constant)
What is an operation
Mathematical calculation involving zero/more input values (operands) that produces an new value
What are expressions
Combination of literals, variables, operators, and function calls that can be executed to produce a singular value.
What is evaluation and result in expressions?
Process of executing an expression is evaluation and the single value produced the result.
What is a user defined function
return-type identifier () { // your code }
Is nest functions supported in C++
No
What is return by value in functions?
Functions will use a return statement to indicated specific values to be returned to the caller. It sends the value.
What are void return values
They tell the compiler that the function does not return a value
What is the return value from
main function
It is called a status or exit code which terminates the program
What are function parameters
They are variables used in functions. Must be initialized with a value provided by the caller of the function
What are local variables?
Function parameters, as well as variables defined inside a function body
What is an identifier’s scope?
Determines where the identifier can be accessed within the source code.
What is a forward declaration
It allows us to tell the compiler about the existence of an identifier before actually defining the identifier
What is a function prototype
Consists of a return type, name, and parameter, but no function body
int add(int x, int y);