Podcast
Questions and Answers
Which of the following best describes the role of the kernel in a computer system?
Which of the following best describes the role of the kernel in a computer system?
- The primary storage device for user data.
- Acts as the medium between hardware and software, managing system resources. (correct)
- The central processing unit responsible for executing instructions.
- The graphical user interface that allows users to interact with the system.
Which of these options is NOT typically a function performed by the kernel?
Which of these options is NOT typically a function performed by the kernel?
- Input/output management.
- Process management.
- Memory management.
- Direct user application development. (correct)
The root directory in a filesystem is represented by a forward slash.
The root directory in a filesystem is represented by a forward slash.
True (A)
In Linux, what does the command mkdir
do?
In Linux, what does the command mkdir
do?
What does sudo
stand for, and what is its primary use?
What does sudo
stand for, and what is its primary use?
In gcc -o output_file source_file.c
, the -o
option specifies the ______ file name.
In gcc -o output_file source_file.c
, the -o
option specifies the ______ file name.
From a program's perspective, how is memory primarily viewed?
From a program's perspective, how is memory primarily viewed?
What is the range of memory addresses a program can access in a 64-bit system?
What is the range of memory addresses a program can access in a 64-bit system?
Match the following memory sections with their typical contents:
Match the following memory sections with their typical contents:
What is the primary purpose of the Heap memory section?
What is the primary purpose of the Heap memory section?
The stack grows upwards in memory.
The stack grows upwards in memory.
Each program has its own view on memory that is ______ of each other.
Each program has its own view on memory that is ______ of each other.
What happens when a program attempts to access a memory address outside of its allocated memory?
What happens when a program attempts to access a memory address outside of its allocated memory?
Which statement is true regarding static libraries?
Which statement is true regarding static libraries?
Dynamic events occur during program building, while static events occur when the program is running.
Dynamic events occur during program building, while static events occur when the program is running.
Which of the following is NOT a valid variable type in C?
Which of the following is NOT a valid variable type in C?
How does C handle integer overflow?
How does C handle integer overflow?
Match the function with what it allows us to perform:
Match the function with what it allows us to perform:
What does the &
operator signify in C?
What does the &
operator signify in C?
In C, the symbol used for the format specifier when printing and scanning variables is the ______ sign (%
).
In C, the symbol used for the format specifier when printing and scanning variables is the ______ sign (%
).
What is the purpose of the #include
directive in C?
What is the purpose of the #include
directive in C?
The #define
directive creates macros which are essentially constant values or expressions.
The #define
directive creates macros which are essentially constant values or expressions.
What is a ternary operator?
What is a ternary operator?
What symbols are used in a ternary expression?
What symbols are used in a ternary expression?
In a ternary expression, the ?
can be considered as '______ then' and the :
can be considered as 'otherwise'.
In a ternary expression, the ?
can be considered as '______ then' and the :
can be considered as 'otherwise'.
Which option correctly identifies the three key aspects of a function?
Which option correctly identifies the three key aspects of a function?
What is the purpose of a function prototype?
What is the purpose of a function prototype?
Explain the difference between passing by value and passing by reference.
Explain the difference between passing by value and passing by reference.
What is recursion?
What is recursion?
What is a pointer?
What is a pointer?
How much memory does a pointer occupy in a 64-bit system?
How much memory does a pointer occupy in a 64-bit system?
In a 64-bit system, an integer typically occupies ______ bytes.
In a 64-bit system, an integer typically occupies ______ bytes.
What is the * symbol known as when used with pointers?
What is the * symbol known as when used with pointers?
What does a pointer typically store?
What does a pointer typically store?
In the declaration int *ptr = &var;
, what is ptr
initialized with?
In the declaration int *ptr = &var;
, what is ptr
initialized with?
What is the difference between (*ptr)++
and *ptr++
?
What is the difference between (*ptr)++
and *ptr++
?
What is a double pointer?
What is a double pointer?
Explain what is happening in the following lines of code:
int var = 10;
int *ptr = &var;
int **dptr = &ptr;
Explain what is happening in the following lines of code:
int var = 10;
int *ptr = &var;
int **dptr = &ptr;
When passing an array to a function, the entire array is copied to the function's local memory.
When passing an array to a function, the entire array is copied to the function's local memory.
When an array is passed to a function, it decays into a ______ to the first element of the array.
When an array is passed to a function, it decays into a ______ to the first element of the array.
What additional information is typically needed when passing an array to a function in C?
What additional information is typically needed when passing an array to a function in C?
Why is sizeof()
used when passing arrays to functions?
Why is sizeof()
used when passing arrays to functions?
When passing an array to a function, what is essentially passed?
When passing an array to a function, what is essentially passed?
Flashcards
What is the kernel?
What is the kernel?
The core of an operating system; like the brain, it manages resources and performs functions.
Kernel functions
Kernel functions
Acts as interface between hardware and software. Includes memory, process, input/output, and file system management.
What is the filesystem?
What is the filesystem?
Hierarchical structure for file organization, with '/' representing the root directory.
ls command
ls command
Signup and view all the flashcards
cd command
cd command
Signup and view all the flashcards
mkdir command
mkdir command
Signup and view all the flashcards
mv command
mv command
Signup and view all the flashcards
cp command
cp command
Signup and view all the flashcards
scp command
scp command
Signup and view all the flashcards
tar command
tar command
Signup and view all the flashcards
rm command
rm command
Signup and view all the flashcards
chmod command
chmod command
Signup and view all the flashcards
cat command
cat command
Signup and view all the flashcards
grep command
grep command
Signup and view all the flashcards
less command
less command
Signup and view all the flashcards
more command
more command
Signup and view all the flashcards
man command
man command
Signup and view all the flashcards
sudo command
sudo command
Signup and view all the flashcards
What is gcc?
What is gcc?
Signup and view all the flashcards
gcc option: -o
gcc option: -o
Signup and view all the flashcards
Program memory view
Program memory view
Signup and view all the flashcards
Memory sections
Memory sections
Signup and view all the flashcards
TEXT section
TEXT section
Signup and view all the flashcards
DATA section
DATA section
Signup and view all the flashcards
BSS section
BSS section
Signup and view all the flashcards
HEAP
HEAP
Signup and view all the flashcards
STACK
STACK
Signup and view all the flashcards
Shared libraries
Shared libraries
Signup and view all the flashcards
Address space
Address space
Signup and view all the flashcards
Accessing a memory gap
Accessing a memory gap
Signup and view all the flashcards
Static libraries
Static libraries
Signup and view all the flashcards
Shared libraries
Shared libraries
Signup and view all the flashcards
Static events
Static events
Signup and view all the flashcards
Dynamic events
Dynamic events
Signup and view all the flashcards
C variable types
C variable types
Signup and view all the flashcards
Integer Overflow in C
Integer Overflow in C
Signup and view all the flashcards
printf() and scanf()
printf() and scanf()
Signup and view all the flashcards
& operator
& operator
Signup and view all the flashcards
% (percent sign)
% (percent sign)
Signup and view all the flashcards
Study Notes
General
- The midterm will be comprehensive
- Familiarize yourself with all concepts
- Review labs and codes that have been covered in class
- Exam questions may involve code, but you won't have to write any
- Code understanding is important; you might be asked for output or to show operations
- The exam includes theoretical and practical questions
- The exam contains ~30 multiple-choice and ~5 open-ended questions
Lecture 1: Kernel and Filesystem
- The kernel is like the brain of a computer system, performing many functions
- Kernel functions include acting as a medium between hardware and software
- Kernel functions include memory management
- Kernel functions include process management
- Kernel functions include input/output management
- Kernel functions include file system management
- The filesystem is represented as a tree
- The root directory is represented by a forward slash: /
Lecture 1: Linux Commands
- ls lists directory contents
- cd changes the current directory
- mkdir creates a new directory
- mv moves files or directories
- cp copies files or directories
- scp securely copies files between hosts
- tar archives files
- rm removes files or directories
- chmod changes file permissions
- cat concatenates and displays files
- grep searches for patterns in files
- less displays file contents one page at a time
- more also displays file contents one page at a time
- man displays the manual page for a command
Lecture 1: Sudo and GCC
- sudo stands for "Super User Do"
- sudo allows you to run a command with elevated privileges
- gcc is a built-in compiler
- GCC (GNU Compiler Collection) compiles source code into machine code
gcc -o <output_file name> <source_file.c>
compiles a C source file-o
specifies the output file name
Lecture 2: Memory Organization
- A program views memory as an array of bytes, ranging from 0 to 2^64 - 1
- Memory is organized into sections known as memory mappings
- TEXT stores instructions that the program runs
- DATA stores initialized global variables
- BSS stores uninitialized global variables, initialized to zeros until assigned a value
- Heap stores memory returned by malloc/new
- Stack stores local variables and return addresses
- Shared libraries (.so files) are not added to the executable file
- Shared libraries consist of definitions and are dynamically loaded at runtime
- The heap is space for dynamic memory allocation, and grows upward
- The stack grows downwards
- Stack stores local variables
- Each program has its own independent view of memory
Lecture 2: Memory Access
- There can be gaps between memory sections without mapping
- If a program accesses a memory gap, the OS sends a SEGV signal
- A SEGV signal typically kills the program and dumps a core file
- Static libraries are not shared, with an instance for each process
- Static Libraries are represented as (.a) files added to the executable
- Shared libraries are shared across different processes
- Only one instance of each shared library exists for the entire system
Lecture 2: Events and Variable Types
- Static events occur during program building
- Dynamic events occur while the program is running
- Variable types in C programming include int, char, double, pointer, string, float, short, long and unsigned
Lecture 2: Integer Overflow
- C handles integer overflow by using two's complement
- The value wraps back to the beginning of the value range
- Inputting 2,147,483,648 results in an output of -2,147,483,648
Lecture 3: Printf, Scanf, and Operators
- printf() prints variables and expressions to standard output (the terminal)
- scanf() takes input from standard input (the console)
- & is the address of operator
- When & is paired with a variable, the memory address is acquired
- % (percent sign) is the format specifier for printing and scanning
Lecture 3: Include and Define
- #include declares preprocessor directives for libraries or files to be used in your code
- #define is a preprocessor directive used to create macros
- Macros are constant values or expressions substituted into your code before compilation
Lecture 4: Ternary Operator
- A ternary is a single-line if-else statement
- The ternary operator uses
?
and:
symbols ?
can be read as "if a then b":
can be read as "otherwise c"variable = (condition) ? Expression2 : Expression3;
is one way of reading "ternary expression"- There are multiple ways of reading a ternary expression
(condition) ? (Expression2) : (Expression3);
, andvariable = Expression1? Expression2 : Expression3;
Lecture 5: Functions
- Functions are blocks of code performing a specific task when called
- A function call has function declaration, function definition and an actual function call
- A function prototype tells the compiler about a function's existence and how to call it
- Without a function defined at the top, there is an implicit declaration warning
- A function prototype tells the compiler that the function exists elsewhere, providing its signature
Lecture 5: Pass by Value vs. Reference
- Passing by value copies the values of function parameters
- New memory is created to store passed-by-value parameters for the function call's duration
- Passing by reference allows a function to operate on the original data
- Pass by reference to modify a variable's value in a function, or to avoid copying large data structures
Lecture 5: Recursion
- Recursion is when a function calls itself
- Recursion breaks complicated problems into smaller, simpler ones
- A recursive function calls itself in its function body and must include the function statments, the base condition and the recursive call
Lecture 6: Pointers
- A pointer is a variable that points to an address in memory
- A pointer uses 8 bytes on a 64-bit system and 4 bytes on a 32-bit system
- An integer uses 4 bytes, and a character uses 1 byte in a 64 bit system
*
is the dereference operator and used to access data stored at a memory address- Pointers store a memory address that we are pointing at
int *ptr = &var
initializes a pointer to point at a variable*ptr = &var
will point to the memory address of&var
ptr
alone produces the memory address of var*ptr
produces the value at that memory address(*ptr)++
dereferences first, adding 1 to the value*ptr++
moves to the next memory address- Unary operators read from right to left
Lecture 6: Double Pointers, Arrays & Functions
- A double pointer is a pointer that stores the memory address of another pointer
- Double pointers manage dynamically allocated memory, pass pointers to functions, or deal with complex data structures
- When passing an array to a function, array decay occurs and the array decays into a pointer to the first element
- The memory address of the first element is passed, so the array isn't copied
Lecture 6: Parameter Sizes
- sizeof() is the total number of bytes of the argument
- sizeof() helps determine the size of an array
- Size of an array can be determined by
sizeof(array)/sizeof(array[0])
Lecture 7: Stack
- The stack stores function local variables, temporary variables, arguments for the next function call and where to return when a function ends
- Push adds data
- Pop removes data
- The compiler manages the stack by having one stack frame each time a function is called, created when a function is called, stacked one on top of another and destoryed at function exit
Lecture 7: Stack Errors
- The stack can run out of stack space
- Code can unintentionally change values on the stack, in some other functions frame or the return address of function
- Memory can be accessed even after the frame is deallocated
Lecture 7: Buffer Overflow
- Occurs when more data gets placed by a program or system process to the stack, and the extra data overflows
Lecture 7: Pointers Efficient for Array Indexing
- Normal indexing needs multiplication to find the correct index
- With pointers, there is no need to multiply
Lecture 7: Malloc
- Malloc dynamically allocates a single large block of memory with a specified size.
- Malloc initializes stored memory in the heap
- Malloc returns a pointer to a block of memory that is suitably aligned for any kind of data object that might be contained in the block
Lecture 7: Pointer Cast Type
(cast_type*)
is needed because malloc returns a pointer- The pointer must cast the appropriate pointer data type to void
Lecture 8: Size of Pointer, Memory Deallocation
- Size of a pointer in a 32 bit system is 4 bytes
- Memory allocated by malloc or calloc is deallocated with free
- Prevents memory objects in memory that are no longer in use by the program but that are not freed
- Not deallocating can result in memory leaks
Lecture 9/10: The Heap Errors
- Heap can run out of space, where malloc returns 0
- Heap data can be unintentionally changed or clobbered
- Memory can be accessed after it is freed
- Code can free memory twice which could cause crashing or corruption
- Failing to deallocate creates a memory leak
Lecture 11: Freeing Memory Errors
- A premature free happens when an object still in use by the program is freed
- A double free happens by freeing an object that is already free
- A wild free happens when there attempts to free a pointer in memory that was not returned by malloc
- Memory smashing occurs when less memory is allocated than will be used
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.