Fundamentals Flashcards
What is the difference between a statement, expression, and function?
A statement is a single instruction terminated with a semicolon.
An expression is a mathematical entity which evaluates to a value; often used within statements.
A function is a collection of statements designed to perform a specific job.
What are libraries?
Groups of functions packaged for reuse
What is an l-value?
A value that has an address in memory. Examples are variables. The ‘l’ refers to the fact that these are the only values which can be on the left side of an assignment statement
What is an r-value?
Any value that can be assigned to an l-value and always evaluates to produce a single value.
What happens to the value already in memory when that memory is allocated?
The preexisting value is NOT overwritten, which is part of why uninitialized variables yield seemingly random ‘undefined’ results.
What does the type specification tell the compiler when declaring a variable?
How much memory to allocate.
What is the difference between a literal and a variable?
A literal always evaluates to itself, while a variable evaluates to its held value.
What is the difference between a unary and binary operator?
A unary operator acts on one operand (i.e. the ‘-‘ symbol when specifying a negative number), while a binary operator acts on two operands (i.e. the ‘-‘ symbol when used to subtract one number from another)
What is a forward declaration?
Declaring a variable before it is used/initialized.
What is a function prototype, an what must it have
A function prototype declares the function but does not implement it. It contains the name of the function along with the parameter types and return types. Parameter names are optional but recommended. They should be declared near the top of a file.
What will happen if a function is defined but not implemented and then called?
The program will compile without error, but the linker will produce the error because it cannot find the function implementation and cannot resolve the function call.
How can a .cpp file become aware of functions in other .cpp files
A .cpp file can become aware of functions in other .cpp files by including a forward declaration of that function.
What is a header file?
Contains only function declarations and NOT implementations. For example, iostream.h declares ‘cout’ (so the compiler is happy) but the implementation is within the runtime support library, which is automatically linked to the program by the linker.
What does a library consist of?
A header file with declarations of public functions and a precompiled object that contains all of the implementation code in machine language.
Why is having a precompiled library beneficial?
They rarely change, and the constant need to recompile them is a waste of time. It also hides source code, which is important for intellectual properties.