Draft!
Students are allowed a single (standard-sized) page of notes, possibly
double-sided. You cannot simply create a verbatim copy of my notes; you
must select key bits of pages and/or write significant parts yourself. You
will be required to turn in the page at the end of the exam.
- See exam 1, exam 2 review
- Memory maps
- Draw a memory map for
double a, *b, **c; b = &a; c = & b; **c = 1.2;
- Declare identifier before can use it
- When can an identifier be used before declaration?
- const
- Is the following legal?
void p(const int &x); p(3);
- Write a function
double
that takes a value (of any
type) and returns that value added to itself without changing the
value. Write a fragment of code applying double
to some
declared, initialize variable, where the type of the variable is in
namespace std
.
- Arrays in C++ vs. Java, allocating array on stack vs. heap
- Declare and define a variable
names
that is an
array of pointers to std::string
values. Allow up to 20
names. Set the first name to your own name, but all of the rest should
be nullptr
.
- C & C++ arrays are passed by reference. Use
a
struct
to create an array that is passed by
value.
- Are Java arrays passed by reference or value?
- Assume you are implementing
void dosomething(int
nums[]);
and write int s = sizeof(nums);
in the
body. What does this set s
to? Is there a way to change
the declaration of nums
so s
gets a different
value?
- Why are arrays not very useful in Java? Why are they more
useful in C++?
- What methods are available for C++ arrays?
- Declaring, dereferencing pointers
- Given char *p, knowing the difference
between p, *p, and &p
- Count number of negative values in an array of doubles without
using []
- nullptr
- Initial value of int xs[100]; (depending on where declared)
- Floating-point constants: 6.022e23
Note 11: C
- goals
- differences, similarities to C++
- compilation units, linker, static, extern
- Explain what the linker does. Give as much detail as you can,
being sure to go beyond "combines object files".
- Makefiles; capturing dependencies and actions, make command
- Write a makefile entry for a command
doit
if doit
reads files p
and q
and generates r
- printf/scanf to print/read an integer, string, character
- arrays vs. pointers, computing addresses
- typedef struct { ... } name;
- passing structs as parameters
- C-style strings, strlen, strcpy, strcat, strcmp
- two-dimensional arrays, computing addresses with 2-d arrays
- #define, dangers of using #define instead of templates
- #if ... #else ... #endif
Note 12: memory in C (& C++), stacks
- be able to explain how stack is managed: what is FP, why FP-1 might
be first local variable, given a layout how is data stored in that layout
(including with pointers)
- memory layout: text, rodata, data, bss, heap, stack
- using malloc and free
Note 13: Overloading/copy/move,
STL, strings
- Rule of 5: what are the items, why they are needed
- recognize move constructor, explain what it does
- write copy constructor
- explain elements of assignment operator
- describe which operator is used in
auto x = a;
vs. x = b;
.
- given std::string x;, risk of storing x.c_str() in
a variable/object
Note 14: Streams, formatting
Note 15: Containers, algorithms
- list<T>::iterator, list<T>::const_iterator,
vector<T>::iterator, vector<T>::const_iterator
- begin: first element
- end: just after last element
- Example: if std::vector<double> nums(100); gives an
array of 100 items, begin() returns &nums[0]
and end() returns &nums[100]
- roll of #include <algorithm>;
esp sort, reverse, fill
- arguments to sort, reverse: iterators
Note 16: Types
- three definitions of a type
- How static, dynamic types work: what has to be done at runtime for
dynamic types, compile time for static types
- advantages, disadvantages of int8_t, int16_t, etc.
- what void* means, how used in C
- differences between C and C++ type systems
- casting using (type)
- Ada and type equivalence rule based on names
- Dangers of Ada's name equivalence type system
- strongly typed: same results on all machines independent of
representations
- what it means to create a function pointer, how it is useful in C
Note 17: How Computers Work
- basic gates: AND, OR, NOT - be able to compute result
- I will give you an interpretation key
- What a MUX does
- Processor elements
- Levels 1-6 of the computing abstraction list