C++ Basics Flashcards
What is the auto keyword? Provide an example.
Auto can be used during assignment to automatically set a variable to the type of it’s assigned variable.
What are the three ways to assign a value to a variable (e.g. int)?
a = 5;
b(3);
c{2};
Can you create a new type?
Yes, with the typedef keyword
What is the alternative way of writing false?
0
What is the alternative way of writing true?
1 (or ‘non-zero’)
What is the structure of a C++ array?
type name [size]
What is a null character in a string?
‘\0’
How do you get the memory address of that variable? E.g. int x = 7;
&x
Why do we need pointers?
-dynamically allocate memory
–you can write programs that can handle unlimited amounts of memory-allow a function to modify a variable passed to it
-easier to pass around the location of a huge amount of data than passing the data itself
How do you define a pointer?
*p;
int *y;
How can we get the content of the memory address pointed to by the pointer?
By using the dereference operator ‘*’
int x = 10; //variable x = 10
int* y = &x; //pointer variable y = Address of x
int z = *y; //z = “value pointed to by y” = x, i.e. z = x;
What is the l-value?
The expression that refer to a memory location e.g. a variable
Can be both side
What is the r-value?
The data stored in some memory address (can only be on the right side)
What are the compound data types in C++?
Any type that isn’t a primitive.
Arrays Char sequences Strings Pointers Dynamic memory Data structures
Can pointers be declared as constants?
Yes but can’t change memory address