Linux Command:
What do you need in the declaration of an array?
type name[SIZE];
How do you initialise an array?
specify 1+ values inside { }
int nums[3] = {1, 2, 3};
How do you access a specific index of an array?
arr[index]
Conditional statements
manipulate control flow of program based on the results of BOOLEAN expressions
While loops
As long as (condition) is met, do (thing)
while(x > 0) {
{
always initialize conditions outside of loop
For loops
do (thing) for (number) times
for (int x = 0; x < 10; x += 1) {
}
Functions
What are some important features?
a chunk of code that does something
FEATURES: parameters, argument, declaration, definition, body, return type
What is the difference between a function declaration and a function definition?
DECLARATION: tells the compiler about the existence of a function and its parameters
DEFINITION: provides the implementation of the function
What do we need for file i/o?
Steps to read from a file
What’s the numonic?
ORC
OPEN the file: connect a filestream to file
READ from file: using cin»_space;
CLOSE: clean up
What operators can we use to read in information from a file?
What is a pointer?
a variable that stores the ADDRESS of another variable
Pointers enable pass-by reference: function can modify variables outside its scope via pointers to those variables
If we want to modify variables, should we pass them by value or reference?
pass by REFERENCE
any modifications happen to the actual variable (changed throughout the code) not the copy
What is pass by value?
pass by value: copy of the variable gets passed into function
What is pass by reference?
pass by reference: pass variable’s ADDRESS in memory
we have direct access to the original variable, not a copy
*
&
ADDRESS of a variable
What is the heap?
What must we do when using the HEAP?
Car *car_array = new Car[3];
How can we check that we have freed all of our heap memory?
use valgrind
What is a struct?
package different types of data
What are the components of a struct definition?
Are structs passed by value or reference?
Structs are passed by value