Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
17 Cards in this Set
- Front
- Back
int i = 2;
int j = ++i; j++; cout << i << " "; cout << j << " "; cout << (&i == &j) << endl; |
3 4 false
|
|
int i = 2;
int& j = ++i; j++; cout << i << " "; cout << j << " "; cout << (&i == &j) << endl; |
4 4 true
|
|
const int a[] = {2,3,4}
creates an array where in C++ |
stack
|
|
final int[] a = {2,3,4}
creates what on where in Java |
reference, heap
|
|
final int[] a = {2,3,4}
changing possible? |
reference to array in Java is immutable, but array contents are mutable
|
|
const int a[] = {2,3,4}
changing possible? |
yes. would change actual array
|
|
int i = 2
int& j = ++i does what |
reference ties j to i (so changing j changes i)
|
|
Object's equals() compares ..., not ...
|
references, not contents
|
|
C++ const vars must be ... when declared
|
initialized
|
|
type*, e.g. int*
means |
reads as pointer to an int and denotes the address of the var which is of type int
|
|
*variable, e.g. *p
|
p is an int* and reads "value at address". So ++p means incrementing the pointer (or address), whereas ++*p means incrementing the value at the address (stored by p) by 1.
|
|
type&, e.g. int& j = ++i
|
this should be read as the "address of an int stored in j has been assigned the incremented value of i", which means i and j are now tied forever so whenever i changes, j changes to match it and vice versa. This also means j is another name for i and cannot be assigned to another value later (I think) and you also can't increment j like ++*j since j isn't an address. It'd the equivalent of saying ++*i which doesn't make sense. If you print both of i and j's address in memory, they both have the same address.
|
|
variable&, e.g. int* p = &j,
|
says that the "address of" j is stored in a pointer to an int and that pointer is called p in this case.
|
|
void g(int* p){ ++p;}
int main () { int j = 3; g(&j); cout << j } prints what |
3
|
|
void g(int* p){ ++*p;}
int main () { int j = 3; g(&j); cout << j } prints what |
4
|
|
void g(int& p){ ++p;}
int main () { int j = 4; g(j); cout << j } prints what |
5
|
|
void h(int& r) is a method whose argument demands a ... that cannot be ...
|
l-value that cannot be 0 since it's a null address
|