ics 45c: mini test 1

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

18 Terms

1
New cards

compare floating data types

  • float < double < long double

  • NO UNSIGNED

2
New cards

compare int data types

  • short int < int < long int/size_t

  • YES UNSIGNED

3
New cards

conditional

if (var < 10)

{

// do smth
}

else

{

// do smth

}

4
New cards

loop

for (int = 0; i < 5; i++)

{

// do smth;

}

5
New cards

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’}

6
New cards

7
New cards

8
New cards

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

9
New cards

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

10
New cards

std::cout

  • character out, sending characters to console (like printf)

  • DONT HAVE TO SPECIFY DATATYPE

  • default aligntment - std::left

  • std::cout « var;

11
New cards

std::cin

  • like scanf, input (reads in from console)

  • std::cin » var;

12
New cards

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

13
New cards

include <smth>

  • looks at specific FOLDER on computer

  • for things u use frequently

  • ex: <stdio.h>

14
New cards

include “smth”

  • for UR files

  • look where ur currently located

15
New cards

header files

# ifndef FILENAME_HPP

# define FILENAME_HPP

void func1();

void func2();

# endif

16
New cards

header guards

main.cpp:

# include “physics.hpp”

# include “physics.hpp”

17
New cards

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

18
New cards

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 = &num; // create ref to num and store it in num_ptr, now points to num.