ecs 32c

studied byStudied by 1 Person
0.0(0)
Get a hint
hint

break linenumber

1/107

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

Studying Progress

New cards
107
Still learning
0
Almost done
0
Mastered
0
107 Terms
New cards

break linenumber

create breakpoint at specified line

New cards
New cards

break file:linenumber

create breakpoint at line in file

New cards
New cards
what does #include do?

reads the content of the header file

New cards
New cards

when do you declare variables?

before use

New cards
New cards

uninitialized variable assumes a…

default value

New cards
New cards

before we leave the os, you must always

free the memory from the heap

New cards
New cards

stack

special type of list where the last element in (push) is the first out (pop)

New cards
New cards

in a stack, you read and write from

the same end of the list

New cards
New cards

what does the following block of code do?

void push(int elem) { stack_buffer[itop++] = elem; }

adds element to top of stack

New cards
New cards

what does the following block of code do?

int pop(void) { if (itop > 0)

return stack_buffer[--itop];

el

return 0; }

remove element from top of stack

New cards
New cards

in a stack, if itop == 0, that means…

the stack is empty

New cards
New cards

when must functions be declared?

before use

New cards
New cards

arguments

local variables, values passed from caller

New cards
New cards

return value

single value returned to caller when function exits

New cards
New cards

void

signifies no return value/arguments

New cards
New cards

strings are stores as

character array

New cards
New cards

what does it mean for a string to be null-terminated?

last character in array is ‘\0’ null (not explicitly in string literals)

New cards
New cards

what does #define msg “hello” do?

defines msg as “hello” throughout source fikle

New cards
New cards

datatype of an onject in memory determines…

the set of values it can have and what operations that can be performed on it

New cards
New cards

operators specify

how an object can be manipulated

New cards
New cards

expressions

a combination of values, variables, operators, and functions

New cards
New cards

variables

a named link/reference to a value stored in the system’s memory or an expression that can be evaluated

New cards
New cards

how does the unsigned version differ from its signed counterparts?

the unsigned version is roughly double the range of its signed counterparts

New cards
New cards

what is this operator? “==”

relational operator meaning “equal to”

New cards
New cards

what is this operator? “!=”

relational operator meaning “not equal to”

New cards
New cards

what is this operator? “&&”

logical operator for “and”

New cards
New cards

what is this operator? “||”

logical operator for “or”

New cards
New cards

logical operator for “!”

logical operator for “not”

New cards
New cards

the for loop has three expressions:

  1. initialization

  2. condition

  3. increment

New cards
New cards

if any of the three expressions in a for loop are left empty,

the condition is assumed to be “true”

New cards
New cards

do-while loop

differs from the while loop - condition evaluated after each iteration. form:

do {

////

} while (condition);

New cards
New cards

what is the “break” keyword?

exits innermost loop or switch statement to exit early

New cards
New cards

variable scope

the region in which a variable is valid

New cards
New cards

variables declared outside of a function have (_) scope

global

New cards
New cards

what is the difference between the “while” loop, “do… while” loop, and “for” loop?

  • while loop tests condition before execution of the block

  • do… while loop tests condition after execution of the block

  • for loop provides intialization, testing, and iteration together

New cards
New cards

goto

allows you to jump conditionally to arbitrary part of your code

New cards
New cards

putchar(c)

puts the character c on the standard output and returns the character printed or EOF on error

New cards
New cards

int getchar()

returns the next character from standard input and returns EOF on error

New cards
New cards

what does this do? a.out < file.txt

known as input redirection. treats file.txt as source of standard input.

New cards
New cards

in printf format specification, what is d and i?

integer

New cards
New cards

in printf format specification, what is x and X?

integer (hex)

New cards
New cards

in printf format specification, what is u?

unsigned integer

New cards
New cards

in printf format specification, what is c?

character

New cards
New cards

in printf format specification, what is s?

string

New cards
New cards

in printf format specification, what is f?

float

New cards
New cards

in printf format specification, what is d?

double

New cards
New cards

in printf format specification, what is e and E?

float(exp)

New cards
New cards

in printf format specification, what is %?

literal %

New cards
New cards

the end of the string is specified using

0

New cards
New cards

int sprintf(char string [], char format[], arg1, arg2)

format specification is the same as printf, and the output is written to string. returns the number of character written or negative value on error.

New cards
New cards

int sscanf(char str[], char format[], arg1, arg2)

the format specification is the same as scanf, and the input is read from str variable. returns the number of items read or negative value on error.

New cards
New cards

we can read data from text/binary files using

fopen()

New cards
New cards

fopen returns a () to the file stream if it exists or () otherwise

pointer; NULL

New cards
New cards

int fclose(FILE*fp)

closes the stream. automatically called on all open files when program terminates

New cards
New cards

int getc(FILE*fp)

reads a single character from the stream and returns the character read or EOF on error/end of file

New cards
New cards

char[] fgets(char line[], int maxlen, FILE*fp)

reads a single line (upto maxlen characters) from the input stream (including linebreak). returns a pointer to the character array that stores the line (read-only). return NULL if end of stream

New cards
New cards

int putc(int c, FILE*fp)

writes a single character c to the output stream, and returns the character written or EOF on error

New cards
New cards

int fputs(char line[], FILE*fp)

writes a single line to the output stream, and returns 0 on success, EOF otherwise

New cards
New cards

int fscanf(FILE*fp, char format[], arg1, arg2)

similar to scanf, sscanf, and reads items from intput stream fp

New cards
New cards

int main(int argc, char*argv[])

argc is the count of arguments, and argv is the array of pointers to each of the arguments

New cards
New cards

pointer

memory address of a variable

New cards
New cards

address can be used to…

access/modify a variable from anywhere

New cards
New cards

strings are stored as…

null-terminated character arrays, where the last character == ‘\0’

New cards
New cards

what are the string copy functions?

strcpy(), strncpy()

New cards
New cards

what are the string comparison functions?

strcmp(), strncmp()

New cards
New cards

what is the string length functions?

strlen()

New cards
New cards

what are the string concatenation functions?

strcat(), strncat()

New cards
New cards

what are the string search functions?

strchr(), strrchr()

New cards
New cards

The average and worst case big-O for quicksort are

  • average: O(nlogn)

  • worst case: O(n^2)

New cards
New cards

how to do quicksort?

  • choose a pivot element

  • move all the elements less than pivot to one side, all elements greater than pivot to other

  • sorts sides individually (recursive algorithm)

New cards
New cards

average big-O for binary search

O(logn)

New cards
New cards

worst case Big-O for binary search:

logarithmic time

New cards
New cards

structure

a collection of related variables (of possible different types) grouped together under a single name

New cards
New cards

struct defines…

a new datatype

New cards
New cards

members of a struct

the variables declared within a structure

New cards
New cards

‘→’ operator

used to access members from structure pointers

New cards
New cards

how to declare arrays of int:

int x[10];

New cards
New cards

declaring arrays of structure

struct point p[10]

New cards
New cards

initializing arrays of int

int x[4] = {0, 20, 10, 2};

New cards
New cards

initializing arrays of structure

struct point p[3] = {0, 1, 10, 20, 30, 12};

struct point p[3] = {{0, 1}, {10, 20}, {30, 12}};

New cards
New cards

the size of a structure is…

greater than or equal to the sum of the sizes of its members

New cards
New cards

union

is a variable that may hold objects of different types/sizes in the same memory location

New cards
New cards

the size of the union variable is equal to

the size of its largest element

New cards
New cards

bit-field

a set of adjacent bits within a single ‘word’

New cards