CS 240

0.0(0)
studied byStudied by 1 person
0.0(0)
call with kaiCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/217

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 5:00 PM on 1/29/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

218 Terms

1
New cards

UNIX

Family of OS that derive from AT&T Unix

  • Includes Linux and its distributions

2
New cards

Unix philosophy

  • OS should have simple tools

  • Each tool has a limited, well-defined function

  • Relationships between programs are stronger than the programs themselves

3
New cards

Main features of UNIX

  • Plain text for storing data

  • Hierarchical file system

  • IPC

  • Smaller, more numerous programs

  • Portability

4
New cards

Kernel (UNIX)

Source code of OS

  • conf: configuration

  • dev: device drivers

  • sys: system kernel

  • h: header files

5
New cards

Components of UNIX systems

  • Kernel

  • Development environment (only on older machines)

  • Commands

  • Documentation

6
New cards

Commands (UNIX)

  • sh: shell (command-line)

  • System and user utilities

  • Document formatting

  • Graphics

  • Communications

7
New cards

Environment variables

Variables added to the command line

8
New cards
$TERM=vt100

Sets terminal to lowest common denominator

  • Corrects an incorrectly set terminal

9
New cards
$PS1

Sets the default command for each prompt

10
New cards
$PS2

Sets the default command on execution error

11
New cards

DISPLAY (Environment Variable)

Default display identifier for X11 programs

12
New cards

HOME (Environment Variable)

Home directory

13
New cards

IFS (Environment Variable)

Returns the internal field separator used for word splitting

14
New cards

LANG (Environment Variable)

Sets the system language

15
New cards

LD_LIBRARY_PATH (Environment Variable)

List of directories used to build a process image

16
New cards

PATH (Environment Variable)

Search path for commands

17
New cards

PWD (Environment Variable)

Current working directory

18
New cards

RANDOM (Environment Variable)

Returns random integer between 0 and 32,767

19
New cards

SHLVL (Environment Variable)

Counts the number of bash instances

20
New cards

TERM (Environment Variable)

Display type

21
New cards

TZ (Environment Variable)

Time zone

22
New cards

UID (Environment Variable)

User ID

23
New cards

C preprocessor

Text file processor used to parse code

24
New cards

Preprocessor directives

Commands in code starting with a #

25
New cards

Including contents of files (C preprocessor)

  • Newer versions allow #embed for binary resource inclusion

#include <file>
#embed <file>

26
New cards

Conditional compilation (C preprocessor)

#if <condition>
#else
#elif <condition>
#endif <condition>
#ifdef <var>
#ifndef <var>

27
New cards

Macro string replacement (C preprocessor)

#define <object/function> <value>

28
New cards

Variadic macro (C preprocessor)

Macro with variable arguments

29
New cards

Macro expansion

Replaces macro tokens with replacement text

  • Strings and comments are ignored

30
New cards

Undefined macro (C preprocessor)

#undef <value>

31
New cards

Line number (C preprocessor)

__LINE__

32
New cards

File name (C preprocessor)

__FILE__

33
New cards

Defined operator (C preprocessor)

defined(<macro>)
defined <macro>

34
New cards

Token stringification (C preprocessor)

# -> str(s)

35
New cards

Token concatenation (C preprocessor)

##

36
New cards

Abort (C preprocessor)

#error

37
New cards

Warning (C preprocessor)

#warning

38
New cards

Chains headers of the same name (C preprocessor)

#include_next

39
New cards

C compilation process

  • Source File

  • Preprocessor

  • Compiler

  • Assembler

  • Linker

40
New cards

Preprocessing

  • Removes comments

  • Expands macros and files

  • Processes conditional compilation

41
New cards

Compiling

C code → Assembly code

42
New cards

Assembling

Assembly code → machine code

43
New cards

Linking

Function calls are linked with their definitions in machine code

44
New cards

Static Linking

All code is copied into one executable file

45
New cards

Dynamic Linking

Only names of shared libraries are added, which are referred to upon execution

46
New cards

Macro

Symbolic variable containing a value, expression, or code

  • Created with #define

  • Substituted during compilation

47
New cards

Convention for macro names

All uppercase with underscores

48
New cards

Types of macros

  • Object-like

  • Chain

  • Multi-line

  • Function-like

49
New cards

Object-like macro

Contains a value or expression

50
New cards

Chain macro

Macro value is dependent on another macro

51
New cards

Multi-line macro

Span multiple lines for readability

52
New cards

Function-like macro

Takes parameters and invoke commands

53
New cards

Pointer

A variable that stores the memory address of another variable

54
New cards

Pointer declaration syntax

<type> *<var_name>

55
New cards
&<var_name>

Returns the memory address (pointer) of a variable

56
New cards

Dereferencing a variable

*<var_name>

57
New cards

Pointer size

  • 32-bit system: 4 bytes

  • 64-bit system: 8 bytes

58
New cards

sizeof()

Returns the number of bytes of a variable or type

59
New cards

Null pointer

Pointer variable that doesn’t point to a memory address

60
New cards

Void pointer

Pointer variable that has no data type

61
New cards

Wild pointer

Pointers that have not been initialized

  • Extremely dangerous

  • Can cause crashes, data aborts, or even data corruption

62
New cards

Dangling pointer

Pointers that were freed

  • Extremely dangerous

  • Can cause crashes, data aborts, or even data corruption

63
New cards

Function pointer

  • Pointer that stores the address of a function

    • Allows for functions to be passed as arguments

    • Dynamic invocation

    • Callback functions

64
New cards

Multi-level pointer

Pointer that points to another pointer

65
New cards

Advantages of pointers

  • Dynamic memory allocation

  • Efficient data collection navigation

  • Easy access to memory

  • Can create complicated data structures

  • Better performance with less code

66
New cards

Disadvantages of pointers

  • Easy to corrupt memory

  • Difficult to understand

  • Vulnerable to memory leaks

  • Accessing pointers takes longer

  • Segmentation faults can occur

67
New cards

Dynamic memory allocation

Memory can be allocated, resized, and freed during runtime

  • Memory is manually controlled

  • Memory is stored in a heap rather than a stack

68
New cards

malloc(<bytes>)

Allocates <bytes> contiguous bytes of memory on the heap at runtime

  • Memory is uninitialized

69
New cards

calloc(<bytes>, <var_size>)

Allocates <bytes> * <var_size> contiguous bytes of memory on the heap at runtime

  • Memory is initialized to 0, or NULL if it fails

70
New cards

free(<pointer>)

Releases memory to the OS

  • Avoids memory leaks

  • Best to set it back to NULL

71
New cards

realloc(<pointer>, <bytes>)

Resizes previously allocated memory block

  • If it fails, memory is not freed automatically

  • Use NULL handling

72
New cards

Issues with dynamic memory allocation

  • Memory leaks

  • Dangling pointers

  • Fragmentation (inefficient use of heap memory)

  • Allocation failures (crashes)

73
New cards

struct <name> {};

Creates a blueprint for data collection

  • No functions allowed

  • Each member has its own memory

  • Dot operator for property access

74
New cards

Union

Members share the same memory

  • Only one value may be used at a time

75
New cards

Union declaration

union <union_name> {}

76
New cards

Union invocation

union <union_name> {}

77
New cards

Danger with manipulating union values

Only the last assigned member holds a valid value

78
New cards

Size of a union

The size of its largest member

79
New cards
typedef <existing_type> <new_type>;

Allows for user-defined datatypes through aliases

80
New cards

Bitfield

Variables that have a fixed size

81
New cards

Bitfield declaration

<data_type> <member_name> : <width>;

  • Should be declared in a struct

82
New cards

Uses for bitfields

  • Saving storage space

  • Transmitting data

  • Encryption

83
New cards

Downsides of bitfields

  • Can lead to overflow or underflow if values exceed bit allocation

  • Cannot be put into an array

84
New cards

UNIX file abstraction

  • A file is a sequence of bytes

  • Everything is a file

85
New cards

Danger with printing variables

Variables must be printed through format specifiers

86
New cards

int size

2 or 4 bytes

87
New cards

float size

4 bytes

88
New cards

double size

8 bytes

89
New cards

char size

1 byte

90
New cards

double format specifier

%lf

91
New cards

Unsigned integer format specifier

%zu

92
New cards

Extended keywords

Controls the memory size of a variable

93
New cards

short (extended keyword)

Narrows value to 2 bytes

94
New cards

unsigned (extended keyword)

Removes negative values but doubles the range

  • 2 or 4 bytes (depending on system)

95
New cards

long (extended keyword)

Widens int to 4 or 8 bytes

  • Depends on system

96
New cards

long long (extended keyword)

Forces int to 8 bytes

97
New cards

long double (extended keyword)

Offers more precision than double

98
New cards

short int format specifier

%hd

99
New cards

unsigned int format specifier

%u

100
New cards

long int format specifier

%ld