• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/62

Click to flip

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;

62 Cards in this Set

  • Front
  • Back

"Let the data structure the program" def

Replace complicated code with an appropriate data structure. Before writing code, understand the input, output, and what the best data structure for the data is.

Unix line ending

"\n"

DOS line ending

"\r\n"

when we create an object the system will allocate space on the

heap

memory leak example

a = malloc(...)


a = NULL;

How would you test a sort?

systematically test the edge cases:


- list of length 0


- list of length 1


- n sorted #s


- n reverse sorted #s


- n identical #s


- n random #s

Testing: the general case is ______ _____

not enough

Why should an ADT be kept in a separate file?

for re-use

symbol table def

stores information about variables, functions, objects, classes, etc.

our header file contains our

public interface

<> tells preprocessor to look in:

system locations

"" tells preprocessor to look in:

current directory

header guard example:

util.h:


#ifndef _UTIL_H


#define _UTIL_H


...


#endif

#pragma use

put at the top of a file to only be included once in compilation

what if 2 separate files happen to use the same identifier for a fcn?

it will compile and create an object file, but the linker will give a multiply defined error

static keyword

private. i.e local use only

every variable has a ____ and a ______ _____

type, storage class

storage class def

determines which functions "know" what vars exist and how long a var "lives" in a pgm

5 storage classes

- auto


- external (NOT extern)


- static


- register


- volatile

all vars declared in a routine are ____ unless declared otherwise

auto

an automatic var has a ______ scope, therefore it's stored in the _____

local, RTS

external def

an variable declared outside a routine

an external variable is stored in

DATA section

keyword for external

no keyword

get an external static variable by

declaring a static variable outside any function

external static variable can only be used by ____ in the same ______

functions, file

global variables def

anything accessible between files

why are global variables bad?

breaking the contract defined through the header. Results in unknown changes

always make external variables _____

static (private)

how to separate a program into multiple files

- ADTs get their own files


- define subsystems and group those


- if they go together in a class, the belong in a module

coupling def

reliance on other modules

higher coupling = more likely to:

be affected by changes

in general, _____ coupling is better

lower

cohesion def

the degree to which a function adheres to 1 task

low cohesion =

doing many independent tasks, resulting in side effects caller wasn't aware of

how to control coupling

ADTs

int a[10];


int *ptr1;


ptr1 = a;




*ptr1 gives me:

contents of a[0]

char *str;


str = "Hello World";




str points to:

the first character in the string

ptr1 = &a[0] then how to get a[1]?

*(ptr1 + 1)

C increments or decrements a ptr in:

multiples of the object size

Why is looping through an array with address arithmetic more efficient?

- Subscripting requires a multiplication and addition


- pointers directly store the address of the obj, no math needed to get to the contents

int a[10];




T/F: a and &a[0] are the same address

T

malloc allocates any # of ________ _______ ______

contiguous memory locations

contiguous memory location def

blocks of memory in sequence.


e.g. an array

i = malloc(10*sizeof(int));


T/F: we can do: i[0], i[1], i[2], etc.

T

T/F: C memory mgmt routines (memcpy, memcmp, memset) have a '\0' check

F

optimization is about:

finding ways to do less work, not to make current work faster

hotspot in code def

called the most or runs the longest

3 ways to optimize for time

1. pre-compute and store info in a table or variable. e.g. constants like pi, length of a string or array, etc.


2. find a better data structure


3. caching

sparse data def

a high percentage of the variable's cells are empty

2 ways to optimize for space

1. use a data structure that uses only the space it needs


2. make the most out of the space we have. e.g. boolean only needs 1 bit

members of a union all share:

the same memory

variables inside a union are:

mutually exclusive

unions are useful for marking ________ objects

polymorphic

disadvantage for mark and sweep GC

scans all memory twice, program freezes while GC is happening

advantage of mark and sweep GC

frees the programmer from manual memory management

IDE stands for

Integrated Development Environment

static when applied to a external variables and functions

limits the scope of the vairable or function to the source file containing its definition

static when applied to a automatic variables

causes the variable to remain in existence and retain its value between function calls

What does DBC's contract guarantee us?

that we always leave an object in a valid state

Problem with goto

our clean-up code gets separated from creation code

defer block

block that holds the cleanup code - put it directly under the creation code