1/17
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
compare floating data types
float < double < long double
NO UNSIGNED
compare int data types
short int < int < long int/size_t
YES UNSIGNED
conditional
if (var < 10)
{
// do smth
}
else
{
// do smth
}
loop
for (int = 0; i < 5; i++)
{
// do smth;
}
arrays
fixed length list of elements of SAME data types stored in CONSECUTIVE memory
diff data types require diff lengths of memory, might not fit
size determined at compile time, NEVER CHANGES
make sure to initialize it, or else computer will assign smth random
int array[5];
char array[] = {‘a’, ‘b’, ‘c’}
malloc()
memory allocate
REQUESTS: a chunk of memory on the STACK/HEAP
ARGS: # of bytes
use sizeof(datatype)
RETURNS: address of 1st byte in chunk, void pointer
void *address = malloc(4);
NEEDS to be converted to pointer of 0desired type to use
if u want int, then int int_address = (int *) malloc(sizeof(int))
this var holds mem address that points to an INT
calloc()
same as malloc(), but useful for arrays
0’S OUT ALL BITS IN THAT MEM LOCATION
void *calloc(size t num, size_t size)
num of elements, size of each element
std::cout
character out, sending characters to console (like printf)
DONT HAVE TO SPECIFY DATATYPE
default aligntment - std::left
std::cout « var;
std::cin
like scanf, input (reads in from console)
std::cin » var;
memset
memory set
sets each byte in range of mem to a SPECIFIC VALUE
void *memset(size_t dest, int ch, size_t count)
dest address to set mem at
value to set mem to
num of bytes to set
int *ptr = (int*)malloc(10*sizeof(int));
memset(ptr, 01, 10*sizeof(int));
sets every byte to 0xFF
include <smth>
looks at specific FOLDER on computer
for things u use frequently
ex: <stdio.h>
include “smth”
for UR files
look where ur currently located
header files
# ifndef FILENAME_HPP
# define FILENAME_HPP
void func1();
void func2();
# endif
header guards
main.cpp:
# include “physics.hpp”
# include “physics.hpp”
dereference pointer
after requesting memory & creating pointer, how to access the acc value at that address
STAR BEFORE THE POINTER
printf(“%d”, *ptr)
c = *p
initialize pointer
int num; // initialize the var
int *num_ptr; // initillize the ptr to the var, allocates space, but nothing pointed to rn
num = 42;
num_ptr = # // create ref to num and store it in num_ptr, now points to num.