Term
What are the 3 general steps in creating an executable? |
|
Definition
1. Preprocessing 2. Compiling 3. Linking |
|
|
Term
|
Definition
Before code is compiled it is given to a program called the preprocessor. The preprocessor edits and manipulates code, setting it up for the compiler. Typically the preprocessor looks for lines that begin with # and alters the code based on these directives. |
|
|
Term
|
Definition
Preprocessed code is given to the compiler, a program that translates C statements into machine instructions. |
|
|
Term
|
Definition
A linker combines the object code produced by the compiler with any additional code needed to create a complete execuatable. This additional code includes things like library functions. |
|
|
Term
What are the three fundamental language features that C relies on? |
|
Definition
1. Directives 2. Fucntions 3. Statements |
|
|
Term
|
Definition
A series of statements grouped together and given a name |
|
|
Term
|
Definition
|
|
Term
|
Definition
A command to be executed when the program runs. |
|
|
Term
Definition: String literal |
|
Definition
A sequence of characters surrounded by "" |
|
|
Term
What are the valid ways to write comments in C? |
|
Definition
/* this is the only valid comment */
some compilers allow // but it is not part of standard C |
|
|
Term
|
Definition
|
|
Term
What is a variable's type? |
|
Definition
A specification of what type of data it will hold |
|
|
Term
|
Definition
a combination of explicit values, constants, variables, operators, and functions that are interpreted according to the particular rules of precedence and of association for a particular programming language, which computes and then produces (returns, in a stateful environment) another value. |
|
|
Term
True/False: An expression of the same type can be substituted wherever a value is needed. |
|
Definition
|
|
Term
Definition: format string |
|
Definition
A string literal which specifies a method for rendering an arbitrary number of varied data type parameter(s) into a string |
|
|
Term
|
Definition
A value that doesn't change during execution |
|
|
Term
|
Definition
A symbol that represents an entity such as variables, functions, and macros. |
|
|
Term
|
Definition
A group of characters that can't be broken up without changing their meaning |
|
|
Term
Definition: conversion specification |
|
Definition
A placeholder, preceded by a %, representing a value to be filled in during printed. The value following the % specifies how the value is convereted from internal form to printed form |
|
|
Term
What forms can a conversion specification have? What do the values mean? |
|
Definition
%m.pX or %-m.pX m: minimum field width p: precision X: conversion specifier -: left align |
|
|
Term
What does p specify when used with %m.pd? What if p is bigger than the length of the value to be printed? |
|
Definition
Minimum number of digits. Output is zero-filled |
|
|
Term
What is the conversion specifier: d |
|
Definition
|
|
Term
What is the conversion specifier: e |
|
Definition
floating point in exponential form |
|
|
Term
What does p indicate in %m.pe? What if p == 0? |
|
Definition
How many digits appear after the decimal. The decimal is not displayed |
|
|
Term
What is the conversion specifier: f |
|
Definition
Floating point in fixed-decimal format |
|
|
Term
What is the meaning of p in %m.pf? What if p == 0? |
|
Definition
Number of digits after the decimal. Decimal is not shown |
|
|
Term
What is the conversion specifier: g |
|
Definition
Floating point in either exponential or fixed decimal format depending on the number of significant digits. |
|
|
Term
Whats the difference between %f and %g when displaying data in fixed decimal format? |
|
Definition
%g won't show trailing zeros |
|
|
Term
|
Definition
Starts at the left of the format string. For each conversion specification it tries to locate an item of the appropriate type, skipping blank spaces if necessary. It reads until it finds a character that cannot be part of the string which it puts back into the buffer. |
|
|
Term
What happens if scanf cannot read an item successfully? |
|
Definition
scanf returns immediately without looking at the rest of the format string or remaining buffer data. |
|
|
Term
What does scanf look for when reading an integer? |
|
Definition
First: a digit or minus sign Reads until a nondigit |
|
|
Term
What does scanf look for when reading a floating point? |
|
Definition
1. a plus or minus sign (optional) 2. a sequence of digits possibly containing a decimal point 3. an exponent (optional) consisting of the letter e, and optional sign, and one or more digits |
|
|
Term
What does scanf do when it encounters a whitespace character? |
|
Definition
One whitespace character in the format string will match any number of whitespace characters in the input |
|
|
Term
What does scanf do if it encounters a non-white-space character in a format string? |
|
Definition
It compares it with the next input character? If the two match, then the non-white-space character is discarded and scanf continues processing the input string. If they do not match, scanf puts the character back in the buffer and aborts. |
|
|
Term
Definition: arithmetic operators |
|
Definition
Operators that perform some mathematical functions (+, -, *, /, %) |
|
|
Term
What is the precedence for arithmetic operators? |
|
Definition
unary +, unary -, *, /, %, +, - |
|
|
Term
What is operator associativity? |
|
Definition
When dealing with multiple operators, precedence is not enough to determine order of operations. Associativity comes into play when an expression contains multiple operators of the same level of precedence, and determines which operation will be evaluated first. |
|
|
Term
What is a left associative operator? |
|
Definition
An operator that groups from left to right. Ex: i - j - k == (i -j) - k |
|
|
Term
Which arithmetic operators are left associative? |
|
Definition
binary +, binary -, *, /, % |
|
|
Term
What is right associativity? |
|
Definition
An operator that groups from right to left.. ex: -+x == -(+x) |
|
|
Term
Which arithmetic operators are right associative? |
|
Definition
|
|
Term
|
Definition
Lvalues are values that have addresses being programmatically accessible to the running program. They are variables or dereferenced references |
|
|
Term
Definition: compound assignment |
|
Definition
An assignment that uses the old value as part of the computation for the new value. Ex += *= ... |
|
|
Term
What is a logical expression? |
|
Definition
An expression that results in true or false (nonzero or 0) |
|
|
Term
What are relational operators? |
|
Definition
A binary operator that tests a relationship between two entities and produces true or false:
<, >, <=, >= |
|
|
Term
What is an equality operator? |
|
Definition
A binary operator that tests equality or lack of equality between two entities: == != |
|
|
Term
What associativity do relational and equality operators have in C? |
|
Definition
|
|
Term
What are the C logical operators? What do they produce? How do they evaluate operands? |
|
Definition
!, &&, || They produce a 1 (true) or a 0 (false) They evaluate any non-zero as true and 0 as false |
|
|
Term
What is a logical short circuit? Which operators perform this? |
|
Definition
In something of the form: expr1 && expr2, if expr1 is 0, expr2 is not evaluated and 0 is returned.
In an expression of the form: expr1 || expr2, if expr1 is non-zero, expr2 is not evaluated and 1 is returned |
|
|
Term
What is the associativity of the logical operators? |
|
Definition
! is right associative &&, || or left associative |
|
|
Term
What is a compound statement? |
|
Definition
A group of statements enclosed by {}, indicating to the compiler that the group is to be treated as a single statement |
|
|
Term
What is the rule for determining which if statement an else belongs to? |
|
Definition
An else is paired with the nearest unpaired if statement |
|
|
Term
What is a conditional expression? What is the conditional operator in C? |
|
Definition
Conditional expression is a compound expression that chooses between two expressions based on the truth value of the first one. evalExpr is evaluated, if its value is non-zero, trueExpr is evaluated and its result is the result of the entire expression. Viceversa for falseExpr.
evalExpr ? trueExpr : falseExpr ; |
|
|
Term
What is a controlling expression |
|
Definition
An expression that is evaluated at some point during each iteration and determines if the loop will continue (expr != 0) or if it will discontinue(expr == 0) |
|
|
Term
What is the comma operator? |
|
Definition
expr1, expr2
expr1 is evaluated and its result is dicarded. Then expr2 is evaluated and its value and type is returned. |
|
|
Term
How does the break statement work? |
|
Definition
When executed, it transfers control just past the end of innermost loop or switch |
|
|
Term
How does the continue statement work? |
|
Definition
When executed, it transfers control to just before the end of the loop |
|
|
Term
What is a null statement? What is it good for? |
|
Definition
An empty statement -just a ; It's useful for creating a loop body that does nothing. |
|
|
Term
What are the two categories of integers? |
|
Definition
Signed (default) and unsigned |
|
|
Term
What are the six combinations of modifiers with int? |
|
Definition
short int unsigned short int int unsigned int long int unsigned long int |
|
|
Term
What is a heuristic for choosing modifiers with int to improve portability? |
|
Definition
For values between -32,768 and 32,767, use int. For all other values use long int |
|
|
Term
What is an integer constant? |
|
Definition
A number that appears in the text of the program.
ex: 10, xABC, 017 |
|
|
Term
How are decimal, octal, and hexadecimal constants differentiated? |
|
Definition
Decimal - contain digits 0-9 and do not start with a 0
Octal - contain 0-7 and start with a 0
Hex - contain 0-9 and a-f and start with a 0x |
|
|
Term
How do you force the compiler to treat a an integer constant as long? Unsigned? |
|
Definition
Follow it with L. Follow it with U.
ex: 15UL == 15ul == 15LU == 15lu |
|
|
Term
What is the conversion specifier for reading/writing an unsigned decimal? unsigned octal? unsigned hex?
What if we want the short or long versions? |
|
Definition
decimal: %u octal: %o hex: %x short: %h[u,o,x,d] long: %l[u,o,x,d] |
|
|
Term
What is the default type for floating point constants? |
|
Definition
|
|
Term
What are the conversion specifications for single precision floating point values? Double precision? Long double? |
|
Definition
single: %f, %g, %e double: %lf, %lg, %le long double: %Lf, %Lg, %Le |
|
|
Term
When should you use l in conjunction with a floating point conversion specification? |
|
Definition
Only with scanf. printf %[e,f,g] can print single and double precision |
|
|
Term
|
Definition
8 bit integers. The C specification does not specify whether they are signed or unsigned. |
|
|
Term
What is the conversion specifier for characters? |
|
Definition
|
|
Term
What functions can you for characters instead of scanf and printf? |
|
Definition
getchar() and putchar(char ch) |
|
|
Term
What is the sizeof operator? |
|
Definition
Allows a program to determine how much memory is required by a particular type |
|
|
Term
What considerations are there when printing a sizeof value? |
|
Definition
The return type is implementation defined. The trick is cast it to a known type before printing. |
|
|
Term
What is the difference between the two types of conversions in C? |
|
Definition
Implicit conversions are performed automatically by the compiler. Explicit conversions are mandated by the programmer. |
|
|
Term
When is implicit conversion performed? (4) |
|
Definition
1. the operands in an arithmetic or logical expression do not match 2. the type of the right side of an assignment doesn't match the type of the lvalue 3. the type of an argument of a function doesn't match the type of the corresponding parameter 4. the expression in a return statement doesn't match the function's return type |
|
|
Term
What is usual arithmetic conversion? |
|
Definition
When binary operators have mixed types, their values are converted to the narrowest type that will accommodate both values. The narrowest type is the one that requires the least number of bytes to store. |
|
|
Term
What is integral promotion? |
|
Definition
When an integer type is converted to a less narrow integer type. If a short int is added to a long int, the short int is promoted to long. |
|
|
Term
When does integral promotion occur? |
|
Definition
Whenever the compiler says it should occur: Logically: when operating with mixed integer types. ex: int + long.. int is promoted to long
Also: short a = 1; short b = 2; a += 2; Will throw a warning because C specification says += returns an int and we are trying to store an int in a short. |
|
|
Term
What are the two cases for usual arithmetic conversions? |
|
Definition
1. The type of either operand is a floating type 2. Neither operand has a floating type |
|
|
Term
What is the promotion chart for floating point types? |
|
Definition
long double ^ double ^ float |
|
|
Term
What is the promotion chart for integers? |
|
Definition
unsigned long int ^ long int ^ unsigned int ^ int |
|
|
Term
What happens when an unsigned integer is mixed with a signed operand? |
|
Definition
Signed operand will be treated as unsigned. The sign bit of the signed operand will be treated a normal bit and produce unexpected results. ex: signed int i = -10; unsigned int j = 10; printf("%d\n", (i < j));
will print 0 instead of 1 |
|
|
Term
What conversion happens in an assignment statement? |
|
Definition
If the rvalue type is different from the lvalue type, the rvalue type is converted to the lvalue type |
|
|
Term
|
Definition
( cast-to-type ) expression |
|
|
Term
What is the purpose of typedef? How do you typedef? |
|
Definition
To give alternate names to existing types.
typdef existing-type symbol |
|
|
Term
Why not just use macros instead of typedefs? |
|
Definition
Type definitions are more powerful. Array and pointer types cannot be defined as macros. Typedef names are subject to the same scope rules as variables. Macros are not and cause unexpected errors. |
|
|
Term
|
Definition
A data structure containing a number of data values, all of which have the same type. |
|
|
Term
What is needed to declare an array? |
|
Definition
1. a type 2. an identifier 3. the size of the array enclosed in brackets OR empty brackets with an initializer |
|
|
Term
What is an array initializer? |
|
Definition
a list of constant expressions enclosed in {} and separated by commas |
|
|
Term
How are multidimensional arrays stored in memory? |
|
Definition
Row major order. Row 1 is ascending index order, then row 2, so on and so on. |
|
|
Term
What is a constant array? |
|
Definition
An array declared const cannot be modified. |
|
|
Term
What is the assumed return type of a function that does not specify its return type? |
|
Definition
|
|
Term
What is a function prototype? |
|
Definition
A way to provide the compiler the way to call a function before we implement it. |
|
|
Term
What is the difference between parameters and arguments? |
|
Definition
Parameters appear in function definitions. They are dummy names for the values passed in the function call.
Arguments are expressions that appear in function calls.
Arguments supply parameters their value. |
|
|
Term
What does "pass by value mean"? |
|
Definition
In each function call, the evaluated argument's value is assigned to the corresponding parameter |
|
|
Term
What is main the implication of pass by value? |
|
Definition
Changes made to the parameter does not affect the value of the argument. |
|
|
Term
How can you write a function that changes values? |
|
Definition
Define a function that takes pointers to the values you want to alter. |
|
|
Term
What does the compiler do if it encounters arguments that don't match the types of the parameters? |
|
Definition
Case 1: The compiler has seen a prototype for the function - The value of each argument is implicitly converted to the corresponding parameter's type
Case 2: The compiler has not seen a prototype for the function - The compiler performs default argument conversion. Floats are promoted to doubles, integral promotions are performed (char/short to int) |
|
|
Term
What happens when an array is passed to a function? |
|
Definition
The function is given a pointer to the first element of the array. |
|
|
Term
What is the value that main returns? |
|
Definition
A status code to the operating system |
|
|
Term
What is the difference between return and exit? |
|
Definition
Exit can be called from any function |
|
|
Term
What is a local variable? |
|
Definition
A variable only accessible in the block in which it is defined. Typically inside a function |
|
|
Term
What are the default properties of a local variable? |
|
Definition
Automatic storage duration Block scope |
|
|
Term
What is storage duration? |
|
Definition
The portion of program execution during which storage for the variable exists. |
|
|
Term
What is automatic storage duration? |
|
Definition
Storage for an auto variable is allocated when the program flow enters its block and is deallocated when flow leaves its block |
|
|
Term
|
Definition
The portion of the program text in which a variable can be referenced. |
|
|
Term
|
Definition
A variable with block scope is only visible from its point of declaration to the end of its block |
|
|
Term
What is a static variable? |
|
Definition
A variable with static storage duration has a permanent storage location. It retains its value throughout the execution of the program. |
|
|
Term
What properties do parameters have? |
|
Definition
Same as local variables: automatic storage duration and block scope |
|
|
Term
What properties do global variables have? |
|
Definition
Static storage duration File scope |
|
|
Term
|
Definition
A variable with file scope is visible from the point of its declaration until the end of the file |
|
|
Term
|
Definition
A compound statement that contains declarations |
|
|
Term
What happens when a variable is declared inside a block that has the same identifier as a variable outside the block? |
|
Definition
The new declaration hides the old one for the duration of the block |
|
|
Term
What is a reference type? |
|
Definition
Every pointer needs a reference type, or rather, a type that the pointer points to |
|
|
Term
What two operators does C provide to work with pointers? |
|
Definition
& - the address of operator, returns the location in memory of its operand
* - the indirection operator, "follows the pointer" to its value |
|
|
Term
How do you prevent a function from changing the value of variable whose pointer was passed to the function? |
|
Definition
Declare the parameter to be const |
|
|
Term
What three forms of pointer arithmetic does C support? |
|
Definition
1. Adding an integer to pointer 2. Subtracting an integer from a pointer 3. Subtracting two pointers |
|
|
Term
What does subtracting array pointers yield? |
|
Definition
The number of elements between the pointers |
|
|
Term
What is the meaning of the expression: *p++ |
|
Definition
value of expression is *p, increment p later |
|
|
Term
What is the meaning of the expression: (*p)++ |
|
Definition
value of expression is *p, increment *p later |
|
|
Term
What is the meaning of the expression: *++p |
|
Definition
increment p, value of expression is *p |
|
|
Term
What is the meaning of the expression: ++*p |
|
Definition
increment *p first, value of expression is *p |
|
|
Term
How would you rewrite a[3] = j using pointers? |
|
Definition
|
|
Term
What is the difference between using the array name and a pointer to the array? |
|
Definition
You cannot assign a new value to the array name. Additionally, int a[10] sets aside 10 memory locations, int *a does not. |
|
|
Term
Why is a[i] equivalent to i[a] |
|
Definition
The compiler treats a[i] as *(a + i) which is the same as *(i + a) |
|
|
Term
What is a string literal? |
|
Definition
A sequence of characters enclosed in "" |
|
|
Term
Why are we allowed to use a string literal whenever a char * is required? |
|
Definition
C treats string literals as character arrays. |
|
|
Term
What is the conversion specification to print or read a string? |
|
Definition
%m.ps m: minimum field width p: print the first p characters s: string |
|
|
Term
Why do you not need to put a & in front of a string variable in scanf("%s", str)? |
|
Definition
str is a character array, thus str is treated a pointer automatically |
|
|
Term
What is important to remember about inputting strings with scanf? |
|
Definition
A string read using scanf will never contain white-space |
|
|
Term
What function should you use to read an entire line of text? |
|
Definition
gets doesn't skip whitespace, it stops reading when it sees a \n (does not include \n) |
|
|
Term
|
Definition
An array whose rows are different lengths. |
|
|
Term
Considering command-line arguments: what is stored at argv[argc]? |
|
Definition
|
|
Term
Why is char *argv[] equivalent to char **argv for command line arguments? |
|
Definition
The arguments are string literals. You reference string literals by pointers to their first character. If you have many arguments, then you need an array of character pointers to access them. C treats array names and pointers in parameters the exact same. |
|
|
Term
What is the preprocessor? |
|
Definition
A program that sets up the source code for the compiler |
|
|
Term
|
Definition
The #define preprocessor directive creates macros - names that represent something else. The preprocessor will expand these macros during preprocessing |
|
|
Term
What are the 6 preprocessor conditional directives? |
|
Definition
#if, #ifdef, #ifndef, #elif, #else, #endif |
|
|
Term
What are the 5 predefined macros? |
|
Definition
__LINE__ __FILE__ __DATE__ __TIME__ __STDC__ |
|
|
Term
What is the #ifdef identifier operator equivalent to? |
|
Definition
|
|
Term
What is the #error directive? |
|
Definition
Indicates a serious flaw in the program and causes most compilers to stop compiling. It prints the message associated with the directive |
|
|
Term
What does the keyword extern do in conjunction with a variable declaration? |
|
Definition
Informs the compiler that the variable is defined elsewhere and there is no need to allocate space for it. |
|
|
Term
How do you protect a header file from being included multiple times? |
|
Definition
Enclose its contents in a #ifndef-#endif block. For example: a header file named stack.h:
#ifndef STACK_H #define STACK_H
stuff
#endif |
|
|
Term
When are header files compiled? |
|
Definition
They aren't. Their contents are compiled along with the file that includes them |
|
|
Term
|
Definition
The linker combines object files created by the compiler into an executable image. The linker is responsible for resolving external references left behind by the compiler from function calls to other files and references to external variables. |
|
|
Term
|
Definition
A file containing the necessary information to build a program. It lists the files and describes their dependencies. |
|
|
Term
What is the format of a make file entry? |
|
Definition
target : dependencies command
example: fmt : fmt.o word.o line.o gcc -o fmt fmt.o word.o line.o |
|
|
Term
How does the makefile know which files to recompile during a rebuild? |
|
Definition
It checks the timestamps of the files to determine which are out of date. |
|
|
Term
What is the primary difference between an array and a structure? |
|
Definition
Structures can be composed of different types |
|
|
Term
What is the primary difference between structs and unions? |
|
Definition
Members of structs are stored at different memory locations, members of unions are stored at the same address. |
|
|
Term
|
Definition
A container that provides context for the identifiers it holds, and allows for the disambiguation of homonym identifiers in different namespaces. |
|
|
Term
How do we access a member of a struct? |
|
Definition
|
|
Term
Are members of structs lvalues or rvalues? |
|
Definition
|
|
Term
How do you create a copy of struct? |
|
Definition
structVar1 = structVar2
assuming they are the same type |
|
|
Term
How do we define and use a structure tag? |
|
Definition
define: struct identifier{ stuff }; use: struct identifier .. |
|
|
Term
How we do define a type name for a struct? |
|
Definition
typedef struct identifier{stuff} Typename; |
|
|
Term
What is the downside to passing a structure to a function or returning a structure from a function? What is a logical improvement to this paradigm? |
|
Definition
The stack frame must allocate space for the structure which can be costly if the structure is large. By passing or returning pointers we can improve performance. |
|
|
Term
What is one of the primary uses of unions? |
|
Definition
They can be used to save space in structures when mutually exclusive members exist. |
|
|
Term
What is one of the major problems inherent with using unions? How do we rectify it? |
|
Definition
There is no way to tell which member of the union was last changed, and therefore contains a meaningful value. The simplest solution is embed a union in a struct where the struct has a tag field indicating which member was last changed. |
|
|
Term
|
Definition
A type whose values are listed and named. |
|
|
Term
What is one of the main functional differences between enumerations and #define constants |
|
Definition
enumerations are subject to C's scope rules |
|
|
Term
What are the 3 ways to define enumerations? |
|
Definition
enum identifier {...}; typedef enum {...} identifier; typedef enum tag {...}identifer; |
|
|
Term
How could you use enum to create a Boolean type? |
|
Definition
typedef enum{FALSE, TRUE} Boolean; |
|
|
Term
How do you alter the values associated with each constant in an enumeration? |
|
Definition
typedef enum{CONST1 = ...}identifier; |
|
|
Term
What is dynamic memory allocation? Where is this memory allocated from. |
|
Definition
The allocation of memory storage for use during the runtime of that program. Its allocated from the heap (usually) |
|
|
Term
What is one of the primary benefits of dynamic memory allocation? |
|
Definition
We can create data structures that grow and shrink during execution |
|
|
Term
What are the three dynamic memory allocation functions and what header are they declared in? |
|
Definition
malloc()
calloc()
realloc()
|
|
|
Term
What is the difference between malloc and calloc? |
|
Definition
malloc allocates a block of memory but doesn't initialize it. calloc allocates a block of memory and clears it |
|
|
Term
|
Definition
Resizes a previously allocated block of memory |
|
|
Term
What do malloc, calloc, and realloc return? What if the memory couldn't be allocated? |
|
Definition
void * a generic memory pointer
if it couldn't allocate the memory -it returns a null pointer |
|
|
Term
What is crucial to do when using memory allocation functions? |
|
Definition
Check to see if the value returned is a null pointer. |
|
|
Term
If p is of type char *, why is it not necessary to cast the void * in p = malloc(sizeof("stuff")); |
|
Definition
There is an implicit conversion when a variable of one type is assigned a variable of another type. |
|
|
Term
How would we use malloc to allocate space for an array of n struct a's? |
|
Definition
struct a *arr = malloc(n * sizeof(struct a)); |
|
|
Term
|
Definition
void *calloc(size_t nelem, size_t size) returns a generic pointer to a zeroed block of memory large enough for nelem number of elements each of size length |
|
|
Term
|
Definition
void *realloc(void *ptr, size_t size) returns a generic pointer to a block of memory previously allocated by a memory allocation function identified by ptr and resized to size |
|
|
Term
What is garbage? How does it relate to memory leak? How do we handle this? |
|
Definition
Garbage is memory that no longer has a pointer to it and therefore can no longer be referenced. Programs that have this scenario have a memory leak. C does not have a garbage collector so we are responsible for freeing memory blocks that are no longer needed. |
|
|
Term
|
Definition
void free(void *ptr) frees the memory identified by ptr. ptr must point to a block that has been previously allocated by a memory allocation function |
|
|
Term
What is the dangling pointer problem? |
|
Definition
When a dynamically allocated block is freed, the pointer still exists but does not point to anything. Attempting to use the pointer again can cause bugs. |
|
|
Term
What is important to remember when a structure has a member that is a pointer to said structure? |
|
Definition
We are required to use a structure tag, and cannot use a type definition. |
|
|
Term
|
Definition
A data structure that has a data part and a pointer to the next node in the list. |
|
|
Term
What is the process of creating a node? |
|
Definition
1. allocate memory for the node 2. store the data in the node 3. insert the node into the list |
|
|
Term
How can you use malloc to create a node? |
|
Definition
struct node *newNode = malloc(sizeof(struct node)); |
|
|
Term
What is the right arrow selection operator? |
|
Definition
->
it is equivalent to (*identifier).element |
|
|
Term
What are the three steps in deleting a node from a linked list? |
|
Definition
1. find the node 2. make the node before the node to be deleted point to the node after the node to be deleted 3. free the memory for the deleted node |
|
|
Term
How do you create a function pointer? |
|
Definition
return-type (*id)(parameter-type, ..); ex: void (*pf)(int) a function pointer to any function that returns void and takes a single int |
|
|
Term
How do you use a function pointer? |
|
Definition
1. define a function pointer void (*fp)(int) 2. assign it a function fp = func; (correct form is use &func, but its not necessary) 3. call the function fp(10); you can use (*fp)(10) |
|
|
Term
What the difference between a declaration and a definition? |
|
Definition
A declaration introduces an identifier and describes its type, be it a type, object, or function. A declaration is what the compiler needs to accept references to that identifier.
A definition actually instantiates/implements this identifier. It's what the linker needs in order to link references to those entities. |
|
|
Term
What is the general form for declarations? |
|
Definition
declaration-specifiers declarators; |
|
|
Term
What are declaration specifiers? What 3 categories do they fall into? |
|
Definition
Declaration specifiers describe the properties of of the items being declared.
They fall into three categories: storage classes type qualifiers type specifiers |
|
|
Term
What are the 4 storage classes? What is the restriction placed on their combination? |
|
Definition
auto, static, extern, register at most one may appear in a declaration |
|
|
Term
What are the 2 type qualifiers? What is the restriction placed on their combination? |
|
Definition
const, volatile any combination may appear in a declaration |
|
|
Term
What are the type specifiers? |
|
Definition
void, char, short, int, long, float, double, signed, unsigned, struct, union, enum |
|
|
Term
|
Definition
In short: identifiers variable names, array names, pointer names, function names, etc. |
|
|
Term
What is the storage duration, scope, and linkage of: a variable declared inside a function |
|
Definition
|
|
Term
What is the storage duration, scope, and linkage of: variables declared outside any block |
|
Definition
|
|
Term
What is the storage duration, scope, and linkage of: a static variable declared outside any block |
|
Definition
|
|
Term
What is the storage duration, scope, and linkage of: a static variable declared inside a block |
|
Definition
|
|
Term
What does the extern storage class enable? |
|
Definition
The sharing of the same variable between files |
|
|
Term
What does putting extern in front of a variable do? |
|
Definition
Indicates to the compiler that the variable is defined somewhere else in the program, and space should not be allocated for it. |
|
|
Term
What storage class do extern variables always have? |
|
Definition
|
|
Term
What determines an extern variables scope? |
|
Definition
The placement of its declaration. Inside a block means block scope, otherwise file scope. |
|
|
Term
What does declaring a variable to have the storage class register mean? |
|
Definition
It _requests_ a variable be stored in a cpu register. |
|
|
Term
Where is the only legal place for a register variable to be declared? |
|
Definition
|
|
Term
What is the storage storage duration, scope, and linkage of a register variable? |
|
Definition
Same as an auto variable. auto block no linkage |
|
|
Term
What is a crucial difference between an auto variable and a register variable? |
|
Definition
You cannot use & with a register variable |
|
|
Term
Why would you use the register storage class? |
|
Definition
Because registers are accessed more quickly than memory, you can use them for variables that are accessed/changed frequently like loop counters |
|
|
Term
What does extern indicate in conjunction with function declarations/definitions? |
|
Definition
It specifies that the function has external linkage, allowing it to be called from other files. |
|
|
Term
What does static in conjunction with function declarations/definitions mean? |
|
Definition
Specifies the function has internal linkage -the function may be called only within the file in which it is defined. |
|
|
Term
What storage class is assumed for functions if no storage class is defined? |
|
Definition
extern, and thus specifying a function to be extern is redundant |
|
|
Term
What is the type qualifer const used for? |
|
Definition
To declare objects that are read-only |
|
|
Term
What does the volatile type qualifer indicate? |
|
Definition
It tells the compiler that the value of the variable may change at any time--without any action being taken by the code the compiler finds nearby. This has implications especially when dealing with compiler optimization |
|
|
Term
What is the rule of thumb for deciphering complex declarations? |
|
Definition
1. Read from the inside out - find the identifier and start from there
2. When there is a choice, favor [] and () over * - if the identifier is *id[] it is an array of pointers not a pointer to an array |
|
|
Term
What is the restriction on initializers for static variables? |
|
Definition
The initializer must be constant |
|
|
Term
What exactly is the difference between "scope" and "linkage"? |
|
Definition
Scope is for the benefit of the compiler, while linkage i for the benefit of the linker. The compiler uses the scope of an identifier to determine whether or not it's legal to refer to the identifier at a given point in a file. When the compiler translates a source file into object code, it notes which names have external linkage, eventually storing these names in a table inside the object file. Thus, the linker has access to names with external linkage; names with internal linkage or no linkage are invisible to the linker. |
|
|
Term
Why can't const objects be used in constant expressions? |
|
Definition
A const object is only guaranteed to stay constant during its lifetime, not throughout the execution of the program. |
|
|
Term
|
Definition
A collection of services, some of which are made available to other parts of the program (clients) |
|
|
Term
What is a module interface? |
|
Definition
A common means for two unrelated modules to interact. |
|
|
Term
What are the two properties that modules should have? |
|
Definition
High cohesion, and low coupling |
|
|
Term
|
Definition
The extent to which elements of a module are related. |
|
|
Term
|
Definition
The extent to which modules are dependent on each other. |
|
|
Term
What are the 4 bitwise operators from highest precedence to lowest precedence? |
|
Definition
|
|
Term
How do you set a bit in a bit string? |
|
Definition
Do a bit wise or with a zeroed string but with a 1 in the position of the bit you want to set |
|
|
Term
|
Definition
Do a bitwise and with a string with all 1's but with a zero in the position you want to clear |
|
|
Term
|
Definition
Do a bitwise XOR with a zeroed string with a 1 in the position you want to flip |
|
|
Term
How can you use bitshifts to create a bit mask? |
|
Definition
If you want a 1 in position j you would do: i = (1 << j)
If you want a zero in position j: i = ~(1 << j) |
|
|
Term
How do you declare a structure whose members represent bit fields? |
|
Definition
struct identifier{ (unsigned) int: #ofbit };
unsigned is optional |
|
|
Term
Why would we need a type qualifier such as volatile? |
|
Definition
If we have a pointer to a volatile memory location, the data at that location can change without program interference. If we write a program that has a pointer to that location and we are continually checking it -the compiler might recognise that we aren't changing the pointer or the pointee and optimize the code by fetching the value once and storing it in a register. This would not be what we want because we would only have the value of the volatile memory address at a specific point in time, and not as it continuously changes. |
|
|
Term
|
Definition
Any source of input or any destination for output |
|
|
Term
How are streams accessed in C? |
|
Definition
Through file pointers... FILE *fp |
|
|
Term
What are the 3 ready-to-use streams provided by stdio.h |
|
Definition
stdin - keyboard stdout - screen stderr - screen |
|
|
Term
What are the two types of files supported by stdio.h? What is the difference between them? |
|
Definition
Text files - Bytes represent characters, making it human-readable
Binary files - Bytes represent other types of data.. ints, floats, etc |
|
|
Term
What are the 6 mode strings? How do you make a mode string for a binary file? |
|
Definition
r - reading w - writing (file need not exist) a - appending (file need not exist) r+ - reading and writing starting at beginning w+ - reading and writing (truncate if exists) a+ - reading and writing (append if exists)
To make a binary mode string, add b to the mode strings listed above. |
|
|
Term
What does freopen do? What is its most common use? |
|
Definition
Attaches a different file to a stream that's already open. Its most common use is to associate a file with one of the standard streams. |
|
|
Term
What is freopen's normal return value? |
|
Definition
It's third argument, a file pointer to a stream like stdout. |
|
|
Term
What does tmpfile from do? |
|
Definition
Returns a pointer to a file that will remain open until its closed or until the program ends. |
|
|
Term
How does output buffering work? |
|
Definition
Data to be stored is written to a buffer. When the buffer is full or the stream is closed, the buffer is flushed (written to device). |
|
|
Term
How does input buffering work? |
|
Definition
Input is put into an input buffer, and input is read from this buffer as opposed to reading from the actual device. |
|
|
Term
What does fflush do? What arguments does it take? What does it return? |
|
Definition
Flushes a file's buffer.
Takes a file pointer or NULL, NULL flushes all buffers.
If it is successful, it returns 0. If there is an error it returns EOF. |
|
|
Term
What is setvbuf used for? |
|
Definition
Allows us to change the way a stream is buffered and to control the size and location of the buffer. |
|
|
Term
|
Definition
characters are transmitted to the system as a block when a buffer is filled |
|
|
Term
|
Definition
characters are transmitted to the system as a block when a new-line character is encountered. Line buffering is meaningful only for text streams and UNIX file system files. |
|
|
Term
|
Definition
characters are transmitted to the system as they are written. Only regular memory files and UNIX file system files support the no buffering mode. |
|
|
Term
What is the benefit of creating a buffer with automatic storage duration? What is the benefit of using a dynamically allocated buffer? |
|
Definition
Using an automatic variable allows space to be reclaimed automatically at the end of the block.
Using dynamically allocated space allows us to reclaim the space when we no longer need the buffer. |
|
|
Term
What is the restriction placed on using setvbuf |
|
Definition
It must be called after the stream has been opened but before any other operations are performed on it. |
|
|
Term
|
Definition
Allows a program to monitor its own behavior and detect possible programs at an early stage. |
|
|
Term
|
Definition
An expression that we expect to be true under normal circumstances. |
|
|
Term
|
Definition
It takes an integer argument(an assertion) that it tests when it executes. If the argument in non-zero: assert does nothing. If it is zero assert prints a message to stderr and calls the abort function to terminate the program. |
|
|
Term
How do you disable assert using 1 line of code? |
|
Definition
Define the macro NDEBUG prior to including
#define NDEBUG #include |
|
|
Term
What is the errno variable? What header is it declared in? |
|
Definition
Some functions indicate failure by storing an error code in the errno variable.
errno is defined in |
|
|
Term
What is important to remember when checking if a function has altered errno? |
|
Definition
You must clear errno before using a function that might change errno. If an error code has been stored in errno prior to calling a function, and the recent function does not return an error code, errno will retain the previous error code. Library functions do not clear errno. |
|
|
Term
What does the signal.h header do? |
|
Definition
provides facilities for handling exceptional conditions, known as signals |
|
|
Term
What are the two categories that signals fall into? |
|
Definition
Run-time errors External events |
|
|
Term
What does it mean that signals can happen asynchronously? |
|
Definition
Signals can be raised at any time during program execution, not just at certain points known to the programmer. |
|
|
Term
What does the signal function do? |
|
Definition
Installs a signal handling function for use later if a given signal should occur. |
|
|
Term
What are the two parameters to the signal function? |
|
Definition
The first is the code for a particular signal (usually a macro) The second is a function pointer to a function that will handle the signal |
|
|
Term
What argument must every signal handling function be passed? |
|
Definition
An int for the signal code that will be passed to the handler. |
|
|
Term
What happens if the signal handling function returns? |
|
Definition
Execution resumes from the point where the signal occurred. |
|
|
Term
What are the two predefined signal handlers provided by signal.h? |
|
Definition
SIG_DFL : the default handler -usually causes program termination
SIG_IGN : specifies the signal code should be ignored should it arise |
|
|
Term
What is the SIG_ERR macro used for? |
|
Definition
It's used to test whether a signal handler can be installed. If it can't signal returns SIG_ERR and stores a positive value in errno. |
|
|
Term
What prevents infinite recursion if the function handler raises a signal? |
|
Definition
C requires that when a handler is called for signals other than SIGILL, the handler be reset to SIG_DFL or blocked in some other way. |
|
|
Term
What has to happen in order for a signal to be handled twice by the same handler? |
|
Definition
The signal handler has to be reinstalled. This can be done at the end of the handler's block. |
|
|
Term
What does the raise function do? What is its argument? What does it return? |
|
Definition
raises causes a signal to occur
its argument is the signal code to be raised
its return value is 0 for success, nonzero for failure |
|
|
Term
What does the setjmp.h header do? |
|
Definition
Makes it possible for one function to jump directly to another function without returning. It's primarily used for error handling |
|
|
Term
What does the setjmp.h header do? |
|
Definition
Makes it possible for one function to jump directly to another function without returning. |
|
|
Term
What does the setjmp function do? How do we use it? What does the longjmp function do? How do we use it? |
|
Definition
setjmp marks a place in a program so we can jump to it later from longjmp. We pass setjmp a variable of type jmp_buf, it then returns 0. longjmp returns to the point where we used setjmp. we use it by passing it the jmp_buf variable we used with setjmp and another int value for the status code. |
|
|
Term
What does the float.h header provide? |
|
Definition
Macros that define the range and accuracy of the floating types. It provides no types or functions |
|
|
Term
What does the limits.h header provide? What doesn't it provide? |
|
Definition
Macros that define the range of each integer and character type. It provides no types or functions. |
|
|
Term
What is does the ctype.h header contain? |
|
Definition
2 kinds of functions: character testing functions character case-mapping functions |
|
|
Term
What is the stdarg.h header used for? |
|
Definition
Writing functions of variable length argument lists. |
|
|
Term
What are the 4 components needed to create a function with a variable length argument list? |
|
Definition
va_list - needed to iterate through the arguments va_start - needed to indicate where the arg list starts va_arg - fetches the arguments and advances the pointer va_end - required to clean up before the function can return |
|
|
Term
|
Definition
The extend to which a variable can be shared by different parts of a program |
|
|
Term
What are the different types of linkage? |
|
Definition
external - shared by several files internal - shared by functions in a file no linkage - belongs to a single function |
|
|