CSCI 2021 Midterm 1

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

1/60

flashcard set

Earn XP

Description and Tags

computer science

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

61 Terms

1
New cards

Main components of a CPU

Control Unit, Arithmetic/Logic Unit, Registers

2
New cards

Role of the Control Unit in a CPU

It directs the operation of the processor by fetching and decoding instructions.

3
New cards

Purpose of pointers in C

Pointers store memory addresses and allow direct manipulation of memory.

4
New cards

Dereference operator (*)

It accesses the value stored at the memory address a pointer holds.

5
New cards

& operator in C

It returns the memory address of a variable.

6
New cards

Declaring a pointer to an int in C

int *p;

7
New cards

Difference between passing by value and passing by reference

Pass by value copies the value, whereas pass by reference uses a pointer to modify the original value.

8
New cards

Size of a pointer on a 64-bit system

Typically 8 bytes.

9
New cards

Void pointer

A pointer that can store the address of any data type, but requires casting before use.

10
New cards

How arrays are stored in memory

Contiguously, with each element placed sequentially in memory.

11
New cards

Function used to dynamically allocate memory in C

malloc()

12
New cards

Action after using malloc()

Use free() to deallocate the memory.

13
New cards

Heap in memory management

A region of memory for dynamically allocated variables that persist beyond function calls.

14
New cards

Stack in memory management

A region of memory for storing local variables and function call frames.

15
New cards

Returning a pointer to a local variable

It leads to undefined behavior because the memory may be overwritten.

16
New cards

How struct members are stored in memory

Struct members are stored contiguously but may have padding for alignment.

17
New cards

Purpose of sizeof() in C

It determines the size of a data type or variable in bytes.

18
New cards

How an integer is stored in memory

As a binary sequence of 0s and 1s.

19
New cards

Hexadecimal representation of 255

0xFF

20
New cards

Binary representation of the decimal number 13

1101

21
New cards

Bitwise OR (|) operator

It sets a bit to 1 if either of the corresponding bits in the operands is 1.

22
New cards

Bitwise XOR (^) operator

It sets a bit to 1 if only one of the corresponding bits in the operands is 1.

23
New cards

Two's complement representation

A way to represent signed integers so that negative numbers are stored as complements of their positive counterparts.

24
New cards

Adding two numbers in two's complement representation

The result follows normal binary addition, and overflow occurs if the sign bit changes unexpectedly.

25
New cards

Arithmetic Logic Unit (ALU)

Performs arithmetic and logical operations within the CPU.

26
New cards

Instruction cycle in a CPU

The process of fetching, decoding, and executing an instruction.

27
New cards

Segmentation fault

A runtime error that occurs when a program accesses an invalid memory location.

28
New cards

How do you initialize a pointer in C?

By assigning it the address of a variable using the & operator, e.g., int *p = &x;

29
New cards

What happens when you dereference an uninitialized pointer?

It leads to undefined behavior, potentially causing a crash.

30
New cards

What is pointer arithmetic?

Operations like addition and subtraction on pointers, adjusting them by the size of the data type they point to.

31
New cards

How does pointer casting work in C?

A pointer can be cast to another type using (type*) syntax, e.g., (char*)ptr.

32
New cards

What is a null-terminated string in C?

A sequence of characters ending with a '\0' character to indicate termination.

33
New cards

How do you pass an array to a function in C?

By passing a pointer to the first element, e.g., func(int arr[]) or func(int *arr).

34
New cards

What happens if you forget to free dynamically allocated memory?

It causes a memory leak, leading to inefficient memory usage.

35
New cards

What is the purpose of calloc()?

It allocates memory and initializes it to zero, unlike malloc().

36
New cards

How do you access a struct member using a pointer?

Using the -> operator, e.g., ptr->member.

37
New cards

What is file I/O in C?

Reading from and writing to files using functions like fopen(), fread(), fwrite(), and fclose().

38
New cards

What is endianess?

The order in which bytes are stored in memory: little-endian (least significant byte first) or big-endian.

39
New cards

Why is hexadecimal commonly used in computing?

It is a compact representation of binary, making it easier to read and write.

40
New cards

How does the left shift (<<) operator work?

Shifts bits to the left, multiplying the number by 2 for each shift.

41
New cards

What is a bit mask?

A value used with bitwise operations to isolate or modify specific bits.

42
New cards

How do you convert a negative decimal number to two's complement?

Invert all bits and add 1 to the result.

43
New cards

Why is two's complement preferred for signed integers?

It simplifies arithmetic operations and avoids duplicate zero representations.

44
New cards

What is the fetch-decode-execute cycle?

The process by which the CPU retrieves an instruction, deciphers it, and executes it.

45
New cards

What is the function of the Program Counter (PC)?

It keeps track of the address of the next instruction to execute.

46
New cards

What is a NULL pointer?

A pointer that does not point to any valid memory location.

47
New cards

What is pointer decay?

The process by which an array name is converted into a pointer to its first element.

48
New cards

Why are all pointer types the same size?

Because they store memory addresses, which have a fixed size on a given architecture.

49
New cards

What is pointer indirection?

Accessing the value at a memory address stored in a pointer using the * operator.

50
New cards

What is a dangling pointer?

A pointer that points to memory that has been freed or is no longer valid.

51
New cards

How can you avoid buffer overflow with strings?

By using functions like strncpy() instead of strcpy() and ensuring proper bounds checking.

52
New cards

What does realloc() do?

It resizes previously allocated memory, copying existing contents to a new location if needed.

53
New cards

What is the difference between shallow copy and deep copy?

A shallow copy copies memory addresses, while a deep copy duplicates the actual data.

54
New cards

How do you write a struct to a file?

Using fwrite() to write binary data directly to a file.

55
New cards

What is the difference between text and binary file I/O?

Text I/O handles data as characters, while binary I/O reads and writes raw memory.

56
New cards

What is the purpose of sign extension?

To correctly extend the sign bit when converting a smaller signed value to a larger type.

57
New cards

What does the term 'word size' mean in computing?

The number of bits a CPU processes at a time, typically 32 or 64 bits.

58
New cards

How does the right shift (>>) operator behave?

It shifts bits to the right, dividing the number by 2 for each shift.

59
New cards

What is a circular shift?

A shift operation where bits that are shifted out are reintroduced on the opposite side.

60
New cards

What happens if an unsigned integer overflows?

It wraps around to 0 and continues from there.

61
New cards

What is the largest positive value a signed 8-bit integer can hold?

127 (01111111 in binary).