single value returned to caller when function exits
15
New cards
void
signifies no return value/arguments
16
New cards
strings are stores as
character array
17
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)
18
New cards
what does #define msg “hello” do?
defines msg as “hello” throughout source fikle
19
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
20
New cards
operators specify
how an object can be manipulated
21
New cards
expressions
a combination of values, variables, operators, and functions
22
New cards
variables
a named link/reference to a value stored in the system’s memory or an expression that can be evaluated
23
New cards
how does the unsigned version differ from its signed counterparts?
the unsigned version is roughly double the range of its signed counterparts
24
New cards
what is this operator? “==”
relational operator meaning “equal to”
25
New cards
what is this operator? “!=”
relational operator meaning “not equal to”
26
New cards
what is this operator? “&&”
logical operator for “and”
27
New cards
what is this operator? “||”
logical operator for “or”
28
New cards
logical operator for “!”
logical operator for “not”
29
New cards
the for loop has three expressions:
1. initialization 2. condition 3. increment
30
New cards
if any of the three expressions in a for loop are left empty,
the condition is assumed to be “true”
31
New cards
do-while loop
differs from the while loop - condition evaluated after each iteration. form:
do {
////
} while (condition);
32
New cards
what is the “break” keyword?
exits innermost loop or switch statement to exit early
33
New cards
variable scope
the region in which a variable is valid
34
New cards
variables declared outside of a function have (_) scope
global
35
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
36
New cards
goto
allows you to jump conditionally to arbitrary part of your code
37
New cards
putchar(c)
puts the character c on the standard output and returns the character printed or EOF on error
38
New cards
int getchar()
returns the next character from standard input and returns EOF on error
39
New cards
what does this do? a.out < file.txt
known as input redirection. treats file.txt as source of standard input.
40
New cards
in printf format specification, what is d and i?
integer
41
New cards
in printf format specification, what is x and X?
integer (hex)
42
New cards
in printf format specification, what is u?
unsigned integer
43
New cards
in printf format specification, what is c?
character
44
New cards
in printf format specification, what is s?
string
45
New cards
in printf format specification, what is f?
float
46
New cards
in printf format specification, what is d?
double
47
New cards
in printf format specification, what is e and E?
float(exp)
48
New cards
in printf format specification, what is %?
literal %
49
New cards
the end of the string is specified using
0
50
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.
51
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.
52
New cards
we can read data from text/binary files using
fopen()
53
New cards
fopen returns a (_) to the file stream if it exists or (_) otherwise
pointer; NULL
54
New cards
int fclose(FILE\*fp)
closes the stream. automatically called on all open files when program terminates
55
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
56
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
57
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
58
New cards
int fputs(char line\[\], FILE\*fp)
writes a single line to the output stream, and returns 0 on success, EOF otherwise
59
New cards
int fscanf(FILE\*fp, char format\[\], arg1, arg2)
similar to scanf, sscanf, and reads items from intput stream fp
60
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
61
New cards
pointer
memory address of a variable
62
New cards
address can be used to…
access/modify a variable from anywhere
63
New cards
strings are stored as…
null-terminated character arrays, where the last character == ‘\\0’
64
New cards
what are the string copy functions?
strcpy(), strncpy()
65
New cards
what are the string comparison functions?
strcmp(), strncmp()
66
New cards
what is the string length functions?
strlen()
67
New cards
what are the string concatenation functions?
strcat(), strncat()
68
New cards
what are the string search functions?
strchr(), strrchr()
69
New cards
The average and worst case big-O for quicksort are
* average: O(nlogn) * worst case: O(n^2)
70
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)
71
New cards
average big-O for binary search
O(logn)
72
New cards
worst case Big-O for binary search:
logarithmic time
73
New cards
structure
a collection of related variables (of possible different types) grouped together under a single name
74
New cards
struct defines…
a new datatype
75
New cards
members of a struct
the variables declared within a structure
76
New cards
‘→’ operator
used to access members from structure pointers
77
New cards
how to declare arrays of int:
int x\[10\];
78
New cards
declaring arrays of structure
struct point p\[10\]
79
New cards
initializing arrays of int
int x\[4\] = {0, 20, 10, 2};
80
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}};
81
New cards
the size of a structure is…
greater than or equal to the sum of the sizes of its members
82
New cards
union
is a variable that may hold objects of different types/sizes in the same memory location
83
New cards
the size of the union variable is equal to
the size of its largest element
84
New cards
bit-field
a set of adjacent bits within a single ‘word’
85
New cards
malloc(size_t n)
allocates blocks of memory, and returns a pointer to unitialized block on success. returns NULL on failure
86
New cards
calloc(size_t size_n size)
allocates an array of n elements each of which is ‘size’ bytes. initializes memory to 0
87
New cards
free()
frees memory allocated to my malloc()
88
New cards
linked list
a dynamic data structure that consists of a sequence of records where each element contains a link to the next record in the sequence
* can be singly linked, doubly linked, or circular
89
New cards
binary tree
a dynamic data structure where each node has at most two children.
90
New cards
a binary search tree
a binary tree with ordering among its children
91
New cards
in a binary tree, usually, all elements in the left subtree are assumed to be (“less”/”more”) than the root element and all elements in the right subtree are assumed to be (“lesser”/”greater”) than the root element
“less”; ”greater”
92
New cards
pointer array
array of pointers
93
New cards
what is: int \*arr\[20\];?
an array of pointers to int’s
94
New cards
what is: char \*arr\[20\];?
an array of pointers to char’s
95
New cards
what is: char \*strs\[10\];?
an array of char arrays (or strings)
96
New cards
stack
a special type of list, where the last element in (push) is first out (pop)
97
New cards
in a stack, where do you read and write from the list?
the same end
98
New cards
store the stack as an…
a array buffer
99
New cards
True or False: Size of short integer and long integer would vary from one platform to another.
True. Depending on the os/compiler/system architechture you are working on, the range of data types can vary.
100
New cards
True or False: A long double can be used if range of a double is not enough to accommodate a real number.