the cherno Flashcards
(23 cards)
What is this an example of?
#include <iostream></iostream>
preprocessor statement
What does this do?
#include <iostream></iostream>
Copy paste the declarations from iostream.h at the top of the file
How does compilation work in C++? Describe all of the steps.
- Process preprocessor statements
- Compile all (or selected) files to .obj binaries
- Linker will combine all .obj files into one .exe or .dll
Give an example of a linker error.
A function or type is declared in a header or other declaration, but no definition could be found in the .obj files.
1 bit
a 0 or a 1
1 byte
8 bits
How many unique values can be stored in 10 bytes?
10 bytes = 80 bits = 2^80 unique combinations = 2^80 unique values
How to find out what the size of a given primitive type is
sizeof(int)
True or false: the size of a long is always the same, regardless of your computer and your compiler.
false! it may differ for different compilers
what is the function of the different primitive data labels?
size, and clues for the programmer and language about how to treat it (i.e. when printing)
Float vs double
float = 4 bytes, double = 8 bytes
To assign a float, you must…
add f to the end of the numeric literal
*var
deref the pointer “var” (i.e. access the value)
int*
declare a pointer (and we want to treat the value at the address llike an int, but there is no guarantee that it will be one)
char&
declares a reference (a wrapper for a pointer that gets one address in its lifetime)
&var
access the address of the value var
NULL
equivalent to 0
Why is this ok?char* myPtr = &someChar;
cout << myPtr << "\n";
char* pointers are treated specially be cout; it will automatically dereferenace it and get the associated char
bool
a 1-bit integer. if it is 0, it is fasle, otherwise it is true
What will happen when this code is run?
int a = 5;
int b = 8;
int& ref = a;
ref = b;
it will set the value at the address of a to 8. it will NOT change where the pointer points.
memset args
memset(address, value, size_of_block)
write a method to take in a int pointer, and increment the value that it points to
void increment(int* ptr)
{
(*ptr)++;
}
write a method to take in an int by reference, and increment the value
void increment(int& i)
{
i++;
}