EXAM 2 Topics Flashcards

1
Q

What is dynamic memory?

A

Memory that is allocated during runtime (the execution of a program).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is malloc?

A

Memory allocation. Used to allocate a specified number of bytes of memory. It reserves space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is calloc?

A

Contiguous Allocation. Similar to malloc, but it also initializes the allocated memory to 0
Initializes null, gets space on heap and returns and puts all 0s/nulls in space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is realloc?

A

Reallocate. Used to resize a previously allocated block of memory. Makes memory bigger or smaller, can’t call realloc on something in stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is free?

A

Deallocates memory previously allocated on heap. One argument, pointer to dynamic memory and return memory back to system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a memory leak?

A

Program allocates memory, but fails to release memory when it isn’t needed. Program holds memory and consumes system resources.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a dangling pointer?

A

Pointer that is still pointing to memory location even after it’s been deallocated. Pointer points to unfreed memory. Set pointers to NULL after memory is freed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the five main stages in program translation?

A

Preprocessor, Compiler, Assembler, Linker, Loader

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the lexical analyzer?

A

Input character stream, outputs token stream. Breaks down into tokens: identifiers, operators, and literals.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the syntax analyzer?

A

Input token stream, output syntax tree I. Checks if syntax adheres to rules, output represents program’s structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the Semantic analyzer?

A

Input syntax tree I, output syntax tree II. Checks for violation of rules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the compiler?

A

Converts human-readable source code into machine executable code. Input C program(.c) output Assembly(.o). CREATES AN ASSEMBLY LANGUAGE PROGRAM.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the preprocessor process?

A

Character stream -> Lexical Analyzer -> token stream -> syntax analyzer -> Syntax tree -> Semantic Analyzer-> intermediate code generator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the assembler?

A

Input Assembly(.o) output Machine Code. Translates assembly to machine code, converts to binary instructions and memory addresses. CREATES AN OBJECT MODULE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the linker?

A

input Machine Code output Executable Load Module(.exe). Has access to Libraries. ‘Links’ different parts of program together so it is runnable. LINKS ALL OBJECT MODULES INTO AN EXECUTABLE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the loader?

A

Input Executable Load Module(.exe) output Memory. Prepares program in memory to be executable. LOADS THE LINKED EXECUTABLE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are binary streams?

A

Raw bytes of data

18
Q

What are text streams?

A

Each byte represents a character

19
Q

What is buffering?

A

Collects and manages data in chunks. Efficient, reduces amount of physical input/output.

20
Q

What is an abstract data type?

A

A description of data structure and operations that can be performed on it. Doesn’t specify details of implementation, just behavior and properties.

21
Q

What are the two types of data structures?

A

Discrete: ints, chars, bools
Scalar: discrete types, and reals

22
Q

What are the data categories?

A

Simple, Primitive, Structured, User-defined.

23
Q

What is type checking?

A

Process of enforcing a languages typing rules.

24
Q

What is a struct?

A

A user defined data type that lets you group together variables of different data types.

25
Q

What is a union?

A

Is similar to structure, however all members of the union are stored in the same memory location so only one member can hold a value at a time.

26
Q

What is the comma operator?

A

’,’ binary operator allows you to evaluate multiple expressions separated by commas.

27
Q

What is binary?

A

Read from right to left, 1 indicates counted number, 0 indicates uncounted number.
Negative Numbers: Signed bit, first bit in sequence, will be 1. Indicating negative.
Ones Complement: Method of inverting binary number to get complement. Change all 0s to 1s and 1s to 0s.
0 111 +7 → 1 000 -7
Twos Complement: Method for representing both positive and negative integers in binary form. Negative numbers are represented by taking one’s complement, then starting from the right flipping bits until you flip a 0.
0 111 +7 → 1 000(ones complement) → 1 001(twos complement) -7

28
Q

What are the bitwise logical operators?

A

~ Complement: when inverting bits (0 to 1, 1 to 0)
| OR: when turning on individual bits 1100 | 0010 → 1110
& AND: when testing individual bits x&0001 → non-zero if rightmost of x is 1, masking collections x & 0x000000ff turn upper 24 bits to 0, keep lower 8, turning off individual bits 1110 & ~0100 = 1110 & 1011 → 1010
^ XOR: reversible, simple encryption. Exclusive either/or (i.e no matching)

29
Q

What are bitwise shift operators?

A

“Pick up” bits and move them left or right by some number of bit positions.
Left shift by N bits: data &laquo_space;N.
Drop N bits from left, fill on right with N new bits.
Right Shift by N bits: data&raquo_space; N.
Drop N bits from right, fill on left with N new bits.

30
Q

What is a preprocessor?

A

Text replacement, syntax analysis, lexical analysis, etc.

31
Q

What is the difference between the top half and bottom half of the compiler?

A

Top-half: Scanner produces token sequence, parser produces parse tree, semantic analysis produces an intermediate language
Bottom-half: Creates the assembly language program

32
Q

What are the translation steps?

A

Scan for tokens
Parse
Analyze semantics
Generate assembly instructions
Write Object Module
Link with libraries
Load module into memory

33
Q

The C language is said to pass arrays by _______ because you can change the array’s contents, but it is really pass by _____

A

reference, value

34
Q

It is not possible to assign to an array variable because its ______ is fixed and immutable

A

address

35
Q

In order to create an ADT, you have to use a _______to define a name that is ______ to the user

A

typedef, opaque

36
Q

In C, the ______ file for an ADT module serves as the ______ for the client

A

header, interface

37
Q

The qualifier _____ makes a name visible only inside the module

A

static

38
Q

The word _____, when applied as a qualifier to a name of some pointer type, makes it illegal to change the value of the _____

A

const, pointer

39
Q

g. It is risky to use the _____ function to measure the size of a C string. That will measure the storage size only for a variable whose type is of array char and tell nothing about a pointer to a char memory block. While you cannot tell the size of memory allocated for the string, you can use the ____ function to get the number of significant characters in the string

A

sizeof, strlen

40
Q

What is a stack?

A

a linear data structure, a collection of items of the same type.

41
Q

The function _____ is used to open a file and has 2 parameters: the _______ and the _____

A

fopen, file location, mode

42
Q

The _____ function is used to write to a binary file and the _____ function is used to read from a binary file

A

fwrite, fread