MOPS FINAL

5.0(2)
Studied by 9 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/162

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 8:41 PM on 12/16/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

163 Terms

1
New cards

How to compile but do not link

gcc -c hello.c

2
New cards

-Wextra

provides extra warnings

3
New cards

How to compile into executable

gcc -o hello hello.c

4
New cards

Compile and link

gcc hello.c

5
New cards

-o

places output into a file whatever the user wants to name

6
New cards

-c

compile into object file but DOESNT link

7
New cards

What type of language is C

Imperative

8
New cards

Header Guard

#ifndef _SOMETHING

#define _SOMETHING

#endif

9
New cards

What is stored on the stack?

Local variables and function-calling sequence

10
New cards

What does Preprocessor do?

Defines macros and libraries.
-file inclusion (#include)
-marco definiton (#define)
-Conditional Compilation (#if, #ifdef, #ifndef, #else, #elif, #endif):

11
New cards

What does Compiler do?

Translates C code into assembly code

12
New cards

What does the Linker do?

Combines object modules and static libraries (archives) into a single load module, which is also in machine language

13
New cards

What is a pointer?

A pointer is a variable that contains the address of some other variable. (* operator - NOT REFERENCE)

14
New cards

What is a reference?

The address that locates a variable within memory. (& operator -> reference operator)

15
New cards

how many process are created here?
for (int i = 0; i < 5; i++) {

    fork();

}

2^5 - 1 = 35

16
New cards

What are the different sections of the program in memory?

text, initialized data, BSS, heap, unallocated space, stack

17
New cards

what is stored in text

machine language of the source code

18
New cards

What is stored in 'data'?

initialized global variables

19
New cards

What is stored on the heap

dynamically allocated storage during program execution

20
New cards

What is unallocated space used for?

Extra space for the heap and stack to use as needed

21
New cards

what is stored on the stack

Local variables and function-calling sequence

22
New cards

What is a primitive data type? Provide 3 examples of primitive data types in C.

Primitive data types are supported by the language itself. They are not user defined.int, float, char, double, void

23
New cards

What is the syntax for a function pointer?

(*)(, , ...);

24
New cards

What are the five main steps of the program translation process in order?

preprocessor, Compiler, Assembler, Linker, Loader

25
New cards

What does the loader do?

- Part of the OS.- If applicable, links a load module with dynamic link libraries (shared libraries)- Runs the program

26
New cards

What is a reference

The address that locates a variable within memory. (& operator -> reference operator)

27
New cards

What is a dereference?

Gets the value of the item at an address (* operator -> dereference operator

28
New cards

What data type does C use for IO?

char

29
New cards

What is the difference between binary and text IO streams?

Binary- byte-oriented (raw bytes, no interpretation by the library) Text- 0 or more lines containing 0 or more characters

30
New cards

What is a process? Who is responsible for process management?

A program executing in memory that uses the following resources to perform tasks.- CPU time- Memory- Files-. The OS is responsible for process management.

31
New cards

What is preemptive and non-preemptive scheduling?

Preemptive - CPU can be forcibly removed from a process

Non-preemptive - CPU is never forcible removed from a process

32
New cards

Segmentation in memory 

an OS technique where a program is divided into variable-sized, logical segments—like code, data, or stack—rather than fixed-size blocks

<p><span>an OS technique where a program is divided into variable-sized, logical segments—like code, data, or stack—rather than fixed-size blocks</span></p>
33
New cards

Virtual Memory

VM is the OS abstraction that provides the illusion of an address space that is contiguous and may be larger than the physical address space. Thus, possible to load entire processes to memory

34
New cards

How does virtual memory work

by allowing a computer to run programs larger than its physical RAM by using a section of the hard drive as an extension of RAM.

35
New cards

Why is segmentation in memory management important

It divides a program into logical, non-contiguous units (like code, data, and stack), allowing for better organization, flexibility, security, and efficient memory usage by enabling independent growth of these units and providing access protection for each segment.

36
New cards

signed

can represent both postive and negative values

37
New cards

unsigned 

can represent only postive ints, up to 255. 

38
New cards

Lexical analysis

The process of converting a sequence of characters into a sequence of tokens, which are defined patterns in programming languages. The sequence of tokens are called lexemes. This is the first step in the compiler

39
New cards

Lexical analyzer output of postion = initial + rate * 60

<id,1> <=> <id,2> <+> <id,3> <*> <60>

40
New cards

Syntax analysis

uses the tokens produced by lexical analyzer and creates a tree representation comprised of its grammatical components (operations )to check its structure against the rules of a formal grammar (order of operations. operations)

41
New cards

syntax analyzer output of <id,1> <=> <id,2> <+> <id,3> <*> <60>

(draw and tree then check with notes)

42
New cards

Semantic analyzer

checks for the meaning and logical consistency of a program after syntax analysis has confirmed its grammatical correctness. It involves checking for errors like type mismatches or using an undeclared variable, ensuring that statements are logically sound and adhere to the language's rules for control structures and data types.

43
New cards

Compiling Occurence

Preprocessing -> Compiling -> Assembly -> Linking → loader

44
New cards

What does Assembler do?

Translates assembly code into a relocatable object module, which are in machine language. produces relocatable object modules (ROMs)

45
New cards

Intermediate code generation

translates high-level source code into a simpler, machine-independent representation (IR), such as syntax tree, three-address code, or bytecode.

46
New cards

Code optimizer

improves the efficiency and performance of the generated executable code without altering the program's intended functionality.

47
New cards

what is Type systems?

A set of rules that assigns types to language constructs to ensure type compatibility

48
New cards

Abstraction 

the process of simplifying complex systems by hiding unnecessary details and showing only the essential features. It involves creating a simplified representation, like a function or class, that handles the complex internal workings so other developers can use it without needing to know the intricate implementation

49
New cards

ADT

abstract data types, a conceptual model for a data type that defines a set of operations and their behavior without specifying how the data is stored or how the operations are implemented.

50
New cards

Union type defintion

a user-defined data type that allows different data types to be stored in the same memory location. Only one can hold a value at a time, key difference between a struct

51
New cards

bitwise operator &

symbol for AND, operator returns a number or BigInt whose binary representation has a 1 in each bit position for which the corresponding bits of both operands are 1.
0010 & 0011 = 0001

52
New cards

bitwise operator ^

Symbol for XOR. compares corresponding bits of two operands and returns a new number where each bit is set to 1 if the bits in the same position are different.
0 ^ 0 = 0

1^1 = 0

1^0 = 1

53
New cards

bitwise operator |

Symbol for OR a binary operation that compares corresponding bits of two operands. It returns a 1 in each bit position if the bit is 1 in either or both operands, and a 0 only if both bits are 0.
0 | 1 = 1
0 | 0 = 0

54
New cards

bitwise operator »  

moves the bits of an integer to the right by a specified number of positions. The rightmost bits are discarded, A right shift on an unsigned integer will fill the leftmost bit with a 0. A right shift on a signed integer will copy the leftmost bit and fill in the leftmost bit with that bit after shifting. This operation is equivalent to integer division by powers of two

55
New cards

What are ADTs comprised of

An Abstract Data Type is a conceptual entity composed of:

- data

- operations on that data

56
New cards

enum. 

a user-defined data type that consists of a set of named integer constants. It provides a way to assign meaningful names to integer values, making code more readable and maintainable.

57
New cards

Register variables

a type of variable that the programmer suggests be stored in a CPU register instead of main memory to improve performance.

58
New cards

Restrict type.

an optimization hint that can be applied to pointer declarations. It informs the compiler that for the lifetime of the pointer, no other pointer will be used to access the object to which it points.

59
New cards

Why use restrict types

reduces the amount of alias pointers (pointers that point to the same memory address)

60
New cards

alias pointers

when multiple pointers refer to the same memory location. This means that changes made to the data through one pointer will be visible when accessed through another pointer that aliases the same location.

61
New cards

Comma Operator

Not the same as seperating params/variables/etc with a comma
lowest precedence of all operators
Allows you to put multiple expressions where a single expression is expected
for (int i = 0, j = 100; i < 10; ++i, --j) { // ... }
first, ++i then —j

62
New cards

malloc

allows a program to request memory from the operating system during execution for dynamic structures and other scenarios.

63
New cards

example of malloc

int* arr;
    int n = 5;

    // Allocate memory for 5 integers
    // n * sizeof(int) calculates the total number of bytes needed
    arr = (int*) malloc(n * sizeof(int));

64
New cards

free

used to deallocate or release the memory that was previously allocated by the dynamic memory allocation functions such as calloc(), malloc(), or realloc()

65
New cards

example of free

arr = (int*) malloc(n * sizeof(int)); 
free(arr);

66
New cards

realloc

function that resizes a block of previously allocated memory. It can be used to either increase or decrease the size of the block. returns pointer to block.

67
New cards

example of realloc

arr = (int*) malloc(n * sizeof(int)); 
int new_size = 10;
int *new_arr = (int *)realloc(arr, new_size * sizeof(int));

68
New cards

dangling pointer

a pointer that points to a memory location that is no longer valid, often because the memory has been deallocated or gone out of scope

69
New cards

bitfield

a feature that allows for the packing of data into memory more efficiently by specifying the exact number of bits a structure member should occupy.

70
New cards

initialize a union

union Data {
int i;
float f;
char str[20];
};

71
New cards

how to access unions

the dot symbol. Data.i = 10;

72
New cards

size of a struct

sum of members bytes

73
New cards

float size

4 bytes / 32 bit

74
New cards

double size

8 bytes, 64 bit

75
New cards

signed

can be positive or negative. The leftmost bit determines if positive or negative.

76
New cards

Enum properties.

Each constant is assigned a default integer starting from 0. Can be overridden. 

77
New cards

Example of enum

public enum DayOfWeek {
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
}

78
New cards

What would the value of WEDNESDAY be?
public enum DayOfWeek {
SUNDAY,
MONDAY=17,
TUESDAY=16,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
};

17

79
New cards

encapsulation in c

done by wrapping data in a structure, achieved by structs and pointers.

80
New cards

#

converts the actual argument into a string literal

81
New cards

##

concats two tokens

82
New cards

What flag is used to add a directory to the list of directories to be searched for header files.

The -I flag

83
New cards

FILE ,LINE and DATE are examples of

metadata

84
New cards

what is the size of a char

1 byte

85
New cards

bitwise n - 1

all the bits from the rightmost set bit (inclusive) to the rightmost end are flipped. The rightmost set bit becomes 0, and all the bits to its right (which were originally 0s) become 1s.

86
New cards

what is the size of long

4 bytes

87
New cards

Calloc

returns a pointer that has dynamically allocated memory for an array and initialize all its elements to zero.

88
New cards

Use of calloc

ptr = (int *)calloc(n, sizeof(int));

N for amount, say 4 then enough memory for 4 ints would be allocated.

89
New cards

unistd.h

Library for execvp().

90
New cards

execvp()

from the library unistd.h, loads the program a POSIX system call used to replace the current process image with a new process image

91
New cards

What is a thread

lightweight process, Threads share executable code, OS level resources, global data, and heap.

92
New cards

What is a zombie process in C

when a process finished the execution but still has entry in the process table to report to its parent process is known as a zombie process.

93
New cards

Why are zombie process bad

uses PID

94
New cards

How to prevent zombie process

The parent process is then supposed to execute the wait() system call to read the dead process’s exit status and other information. This allows the parent process to get information from the dead process. After wait() is called, the zombie process is completely removed from memory.

95
New cards

wait()

The wait() method stops a thread's execution until notify() or notifyAll() is called or a state change, releasing the lock on a resource. If nothing, the child will return.

96
New cards

notify()

97
New cards

What is deadlocking in terms of threads?

This situation arises when two or more threads are blocked indefinitely, each waiting for a resource that the other has locked.

98
New cards

What is race conditions in terms of threads?

This is the most common issue, occurring when multiple threads access and modify shared data simultaneously.

99
New cards

Segmentation fault

a type of runtime error that occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not permitted.

100
New cards

How can segmentation faults occur?

Dereferencing a null pointer, buffer overflow, stackoverflow, dangling pointer and etc

Explore top flashcards

flashcards
US History 1920s
36
Updated 1210d ago
0.0(0)
flashcards
unit 2 olivia flashcards
130
Updated 495d ago
0.0(0)
flashcards
KNES 260 LAB MIDTERM
220
Updated 393d ago
0.0(0)
flashcards
BIS Final Acronyms
40
Updated 831d ago
0.0(0)
flashcards
ELA R&J Act 3-5 Vocab
30
Updated 1049d ago
0.0(0)
flashcards
WWI Test
24
Updated 1138d ago
0.0(0)
flashcards
trajet 2 voc
104
Updated 1204d ago
0.0(0)
flashcards
HMH Module 5 Week 2 Vocabulary
32
Updated 294d ago
0.0(0)
flashcards
US History 1920s
36
Updated 1210d ago
0.0(0)
flashcards
unit 2 olivia flashcards
130
Updated 495d ago
0.0(0)
flashcards
KNES 260 LAB MIDTERM
220
Updated 393d ago
0.0(0)
flashcards
BIS Final Acronyms
40
Updated 831d ago
0.0(0)
flashcards
ELA R&J Act 3-5 Vocab
30
Updated 1049d ago
0.0(0)
flashcards
WWI Test
24
Updated 1138d ago
0.0(0)
flashcards
trajet 2 voc
104
Updated 1204d ago
0.0(0)
flashcards
HMH Module 5 Week 2 Vocabulary
32
Updated 294d ago
0.0(0)