CSC 230 Exam 1 Study Guide Cards

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

1/132

flashcard set

Earn XP

Description and Tags

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

133 Terms

1
New cards
Describe the phases of compilation going from source code to an executable program, along with relevant intermediate files (e.g., libraries, object files).
1) A C compiler translates a compilation unit (.c file) into an object file (.o)

2) A Linker then combines the object files with other objects or libraries into an executable program

3) Executable is ready to run. Load and start it up.
2
New cards
Show how to invoke the gcc compiler to compile a program
gcc -Wall -std=c99 name.c -o name
3
New cards
Describe the role of the C preprocessor
Operates on the C source code before the compiler sees it. Includes headers and macros in code.
4
New cards
Define preprocessor macros to serve as named constants.
\#define NAME 12\`
5
New cards
Describe the process of tokenization
Tokenization is the process of breaking source code into tokens.
6
New cards
What types of tokens is the source code broken into?
identifiers, keywords, literal values, operators, and explicit separators
7
New cards
Summarize the history of the standardization of C (informal → C89 → C99)
C was developed with Unix OS to be used as an alternative to developing the OS in assembly. The language then had an informal standard for 10 years until the C89 standard was created in 1989/1990. C99 was then created in 1999 and made the standard.
8
New cards
Describe the difference between statically-allocated and stack-allocated (auto) variables. Explain what language syntax creates each type of variable and the differences in initialization and lifetime between these two types of variables.
Statically allocated variables contain the keyword static and have the lifetime and initialization of a global variable but the scope of a stack variable.  \n

Stack-allocated variables use the auto keyword and are initialized every time control passes through the declaration. Last as long as the function its in and no longer.
9
New cards
Recognize where local (auto) variables may contain undefined values if they are not initialized and why this occurs.
Local variables are undefined when the variable has not been initialized. This occurs because initializing a variable gives it a start value and until it has been initialized, the variable can be anything you want it to be.
10
New cards
Identify the scope of program labels
* You can go to a label at any point in a function however you cannot go to a label in a different function.
* Global variables have a global scope, meaning that any part of the code can access this variable.
* Local variables have a scope of the brackets that surround them
* Static local variables have the scope of a local variable.
11
New cards
Explain what it means for one variable to shadow another and how the compiler decides which variable is currently in scope.
If 2 variables have the same name and overlap in scope, the compiler is going to use the variable with the narrower scope.
12
New cards
Identify and describe the structural components of a C program including implementation files (.c), header files (.h), functions, includes and preprocessor macros and directives.
* Implementation files are the .c files, contain header files (.h) which get translated into object files (.o) through the C Compiler.
* Implementation files contain program functions, include statements and preprocessor macros/directives
* Header files (.h) contain function statements and advertise what all implementation file will contain
* Uses the keyword extern to indicate that the statements in the header file are found elsewhere.
* Object files (.o) are then sent through the linker, which uses a makefile to connect all of the components of the program.
13
New cards
Compare definition and declaration of symbols.
Definitions say that there is a thing and that the program needs to allocate space or write code for it. (have brackets)

Declarations say that there is something like this, but its defined elsewhere. (Kinda just statements with no code other than the statement)
14
New cards
Describe and use function prototypes
Function prototypes are used to tell the compiler about a functions return type without seeing the entire function
15
New cards
Describe and use extern variable declarations
Extern variable declarations tell the compiler that certain functions and variables are visible to multiple source files.
16
New cards
Describe the job of a header file, what things a header might normally contain.
Header files (.h) advertise what all the implementation file will contain. It normally contains function prototypes and extern variable declarations.
17
New cards
What part of the standard library is declared in stdlib.h?
general language features for C
18
New cards
What part of the standard library is declared in stdio.h?
functions for input and output
19
New cards
What part of the standard library is declared in stdbool.h?
constants for true and false and renames _Bool
20
New cards
What part of the standard library is declared in limits.h
Specifications to the limits of what a certain variable can contain.
21
New cards
What part of the standard library is declared in math.h
Various math functions like trig and exponents
22
New cards
Define internal linkage and use static to mark variables and functions with internal linkage.
Internal linkage is when a global variable or function is made static, making it invisible to the linker.
23
New cards
What is a compile-time error?
Compile time errors are when the compiler sees you using a variable/function it has never heard of, like an implicit declaration
24
New cards
What is a link-time error?
Link time errors are when the linker cannot find a definition for a function, like an undefined reference
25
New cards
What are the 3 Fundamental Types for variables
signed, unsigned, and floating point
26
New cards
What is the literal value for an unsigned value
U
27
New cards
What is the literal value for a long variable?
L
28
New cards
What is the literal value for a long long?
LL
29
New cards
Describe the encoding of characters in ASCII
* ASCII has a numeric code for every character, where every numeric code for each character is represented as a hexadecimal.
30
New cards
Describe the representation of strings and make judgements about their size in memory
Strings are arrays of characters. A null character at the end of the string signals when the string ends in memory. You can get its size in memory with a size_t and the sizeof() method.
31
New cards
Describe important features of the ASCII character code, including how digits, letters and special characters are represented
* Letters and digits are in consecutive order
* Capital and lowercase characters are in different parts of the table
* Lower number codes are for control characters
32
New cards
Describe how floating point numbers are represented
Floating point numbers are represented with the floating point type, this variable type has a greater range than both unsigned and signed, but cannot represent every value exactly
33
New cards
Describe the magnitude and precision trade-offs between the floating-point types, float, double and long double
Floats have the smallest amount of space for the mantissa and exponent, while long doubles have the most space.
34
New cards
Determine the order of evaluation for a C expression.

1. Statement termination
2. Parenthesis around a condition evaluation
3. Evaluation of all arguments to a function
4. Returning a value from a function


1. &&, ||, ternary operator, commas (a, b)
35
New cards
Describe the rules for the usual arithmetic conversions

1. Use the widest of the types if it will hold the value


1. Do not use types smaller than int
2. If the signs are mixed, use unsigned
3. If any value is a FPV, convert to a FPV and if both are FPV convert to the wider one
36
New cards
All types of implicit conversions the compiler may introduce in the expression.

1. C will convert values of certain types to the type of the variable it is assigned to.
2. Values passed as parameters get converted to the types the parameters were expecting.
3. The return statement will convert to the return type if possible.
37
New cards
Use constant expressions and identify places where they are required.
Constant expressions are expressions with values that are determined at compile time (cases in a switch statement)
38
New cards
Describe sequence points in C
Sequence points are places where you are guaranteed that all previous operations leading up to that point have been completed.
39
New cards
Reason why a pass-by-reference mechanism is needed for scanf().
The pass-by-reference is needed to actually change what is inside of the variable instead of the variable itself.
40
New cards
Describe what happens internally when a function call is made.
When the function call is made, the compiler writes code to

* Compute and save the actual parameters
* Save the return address in the caller
* Jump to the starting address of the function
* Allocate space for the function’s local variables
* Run the body of the function
* Save the function’s return value
* Free space for local variables
* Jump back to the saved return address.
* Free space for the parameters and return address
41
New cards
Describe what we mean by the type of a function, what parameter types a function may take, what types of values a function can return.
The type of a function is the return type. A function take return and use parameters of all types.
42
New cards
Describe the difference between formal parameters and actual parameters.
Formal parameters are the parameters the function wants you to use. The actual parameters are the parameters the function actually uses.
43
New cards
Describe what a prototype is for
Function prototypes are used to tell the compiler about a function type without seeing the entire function.
44
New cards
Describe how recursive functions are handled via stack allocation and how limits on stack size limits on recursion depth
Deeply nested recursive methods can cause the stack to use up all of its memory. Arrays of huge sizes also waste memory in the stack.
45
New cards
Describe and use the IEEE single (float) precision format.
1 bit for the sign
23 bits for the mantissa
8 bits for the exponent
46
New cards
Describe and use the IEEE double precision format.
1 bit for the sign
52 bits for the mantissa
11 bits for the exponent
47
New cards
Describe overflow with FPVs and identify cases where it will happen
Overflow for FPV can happen with operations that steadily increase an FPV.
48
New cards
Describe underflow with FPVs and identify cases where it will happen
Underflow for FPV can happen with operations that steadily decrease a FPV.
49
New cards
Describe how arrays are stored in memory
Arrays can be stored in the stack or statically as one long line
50
New cards
How does stack-allocation work with arrays
It can store arrays but it will take up huge amounts of memory if they get too big.
51
New cards
Describe the size of the array
The size of the array is gotten from the sizeof() method and is the amount of memory the array takes up
52
New cards
Describe the C policy on bounds checking with arrays
C does no bounds checking for array access in C
53
New cards
How indexing off the ends of an array may affect other variables and program execution.
It can cause you to change the values of other variables in the program or cause a segmentation fault.
54
New cards
Describe where variable-sized arrays can be created.
Variable size arrays can be created in arrays that are stack-allocated.
55
New cards
Describe a buffer overflow and identify cases of buffer overflow vulnerability in code.
Buffer overflow happens when you index out of the array and into memory. Some examples are from getting user input for words or values
56
New cards
Use sizeof() to compute the number of elements in an array.
len = sizeof( b ) / sizeof( b\[0\] );
57
New cards
Describe the difference between an array declared in a function and an array passed to a function as a parameter
Arrays in parameters have the first set of brackets be blank because that determines the array range, which the compiler does not check for.
58
New cards
Describe how the difference between parameter arrays and declared arrays affects sizeof() results.
Arrays passed into a method as a parameter do not have a definite size for one of its boxes, making the normal way to calculate length of an array obsolete. You must pass the array length in as a parameter.
59
New cards
In an array parameter to a function, describe what parts of the array parameter syntax (what dimensions) are required and why.
dimensions for all but the first box are required because the first box determines range and the array does not bounds
60
New cards
Make judgments about the size of a pointer on the common platform
Pointers have the size of the type of element they point to
61
New cards
What is the name of the & in pointers?
address-of operator
62
New cards
What is the name of the \* in pointers?
Type operator
63
New cards
Identify valid and invalid syntax for working with pointers.
type \* identifier
64
New cards
Describe what the null pointer is for
NULL pointer is used for sorting and pass-by-reference
65
New cards
What can you assign the NULL pointer to
Any other pointer
66
New cards
Can you dereference a NULL?
no
67
New cards
Describe the consequences of using an uninitialized or otherwise invalid pointer
Uninitialized pointers have no idea where they are pointing, which might cause it to read or write to an unexpected memory location
68
New cards
Describe the meaning of the const keyword
Const tells the compiler to not let it change the specified value in its runtime.
69
New cards
how is the const keyword typically used as part of the type of a function parameter.
It is used to keep the function from changing a value passed as a parameter
70
New cards
Describe how strings are represented in C
Strings are stored as character arrays in C with a null at the end
71
New cards
How are strings stored in a character array
Each index has a character value assigned to it, and has a null placed at the index after the end of the string
72
New cards
Make judgments about the length of a string that can be stored in an array, based on its size
You can use the method strlen() to get the number of characters in a String
73
New cards
Define a repository
Storage system where master copies of project files are maintained, along with a revision history
74
New cards
Define commit
The act of collecting, and putting all of the files being worked on into the repository at one time.
75
New cards
Define clone
Making a local copy of a repository to work on.
76
New cards
Define pull
Getting code revisions down from the remote repository.
77
New cards
Define push
Putting revisions to code onto the remote repository
78
New cards
What does Centralized Revision Control do?
Contains a server where the projects repo lives. TO work on a shared project, developers pull from the project and commit to the repo
79
New cards
What does Decentralized Revision Control do?
Allows every developer to have their own repository, allowing each developer to commit locally.
80
New cards
 Describe and use the nm command
81
New cards
When we compile a C program with gcc, we normally give the compiler two command-line options, the -Wall option enables additional warnings. The other option says that we would like to use the _______ standard of the C language
C99
82
New cards
As a unary prefix operator, \* is called the ___________ operator
pointer dereference
83
New cards
Typically, setting a pointer to the value____ indicates that it doesn’t point to anything.
NULL
84
New cards
An auto variable is allocated in a region of the program’s memory called the ______
stack
85
New cards
During execution of a Java program, the Java virtual machine will load additional components as they are needed. In general, C programs don’t work like this. The_______ is responsible for combining all the needed components into an executable before execution.
linker
86
New cards
Consider the following code fragment. ________- occurs when you assign from x to y. It involves copying the high-order bit of x into the additional bits to the left in y.

int y;

short x = -50;

y = x;
sign extension
87
New cards
Overflow depends on…
Whether the addition is signed or unsigned
88
New cards
syntax for the constant used to signify a successful exit status
EXIT_SUCCESS
89
New cards
syntax for the constant used to signify a failed exit status
EXIT_FAILURE
90
New cards
syntax for the function that allows the user to exit from a function and program immediately
exit(int status);
91
New cards
True or False: Reading and writing to the terminal or a file looks the exact same to a program
True
92
New cards
Syntax for redirecting input from the terminal to a file
./program < input.txt
93
New cards
Syntax for redirecting output from the terminal to a file
./program > output.txt
94
New cards
syntax for getting one character from standard input
getchar();
95
New cards
What does getchar() return if there is no more input?
The constant EOF (which is -1)
96
New cards
What does getchar() return when successful?
An integer representing the read character
97
New cards
Syntax for printing one character to the terminal
putchar(int ch);
98
New cards
escape sequence for a null character
\\0
99
New cards
escape sequence for a single quote
\\’
100
New cards
escape sequence for double quotes
\\“