1/60
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Main components of a CPU
Control Unit, Arithmetic/Logic Unit, Registers
Role of the Control Unit in a CPU
It directs the operation of the processor by fetching and decoding instructions.
Purpose of pointers in C
Pointers store memory addresses and allow direct manipulation of memory.
Dereference operator (*)
It accesses the value stored at the memory address a pointer holds.
& operator in C
It returns the memory address of a variable.
Declaring a pointer to an int in C
int *p;
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.
Size of a pointer on a 64-bit system
Typically 8 bytes.
Void pointer
A pointer that can store the address of any data type, but requires casting before use.
How arrays are stored in memory
Contiguously, with each element placed sequentially in memory.
Function used to dynamically allocate memory in C
malloc()
Action after using malloc()
Use free() to deallocate the memory.
Heap in memory management
A region of memory for dynamically allocated variables that persist beyond function calls.
Stack in memory management
A region of memory for storing local variables and function call frames.
Returning a pointer to a local variable
It leads to undefined behavior because the memory may be overwritten.
How struct members are stored in memory
Struct members are stored contiguously but may have padding for alignment.
Purpose of sizeof() in C
It determines the size of a data type or variable in bytes.
How an integer is stored in memory
As a binary sequence of 0s and 1s.
Hexadecimal representation of 255
0xFF
Binary representation of the decimal number 13
1101
Bitwise OR (|) operator
It sets a bit to 1 if either of the corresponding bits in the operands is 1.
Bitwise XOR (^) operator
It sets a bit to 1 if only one of the corresponding bits in the operands is 1.
Two's complement representation
A way to represent signed integers so that negative numbers are stored as complements of their positive counterparts.
Adding two numbers in two's complement representation
The result follows normal binary addition, and overflow occurs if the sign bit changes unexpectedly.
Arithmetic Logic Unit (ALU)
Performs arithmetic and logical operations within the CPU.
Instruction cycle in a CPU
The process of fetching, decoding, and executing an instruction.
Segmentation fault
A runtime error that occurs when a program accesses an invalid memory location.
How do you initialize a pointer in C?
By assigning it the address of a variable using the & operator, e.g., int *p = &x;
What happens when you dereference an uninitialized pointer?
It leads to undefined behavior, potentially causing a crash.
What is pointer arithmetic?
Operations like addition and subtraction on pointers, adjusting them by the size of the data type they point to.
How does pointer casting work in C?
A pointer can be cast to another type using (type*) syntax, e.g., (char*)ptr.
What is a null-terminated string in C?
A sequence of characters ending with a '\0' character to indicate termination.
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).
What happens if you forget to free dynamically allocated memory?
It causes a memory leak, leading to inefficient memory usage.
What is the purpose of calloc()?
It allocates memory and initializes it to zero, unlike malloc().
How do you access a struct member using a pointer?
Using the -> operator, e.g., ptr->member.
What is file I/O in C?
Reading from and writing to files using functions like fopen(), fread(), fwrite(), and fclose().
What is endianess?
The order in which bytes are stored in memory: little-endian (least significant byte first) or big-endian.
Why is hexadecimal commonly used in computing?
It is a compact representation of binary, making it easier to read and write.
How does the left shift (<<) operator work?
Shifts bits to the left, multiplying the number by 2 for each shift.
What is a bit mask?
A value used with bitwise operations to isolate or modify specific bits.
How do you convert a negative decimal number to two's complement?
Invert all bits and add 1 to the result.
Why is two's complement preferred for signed integers?
It simplifies arithmetic operations and avoids duplicate zero representations.
What is the fetch-decode-execute cycle?
The process by which the CPU retrieves an instruction, deciphers it, and executes it.
What is the function of the Program Counter (PC)?
It keeps track of the address of the next instruction to execute.
What is a NULL pointer?
A pointer that does not point to any valid memory location.
What is pointer decay?
The process by which an array name is converted into a pointer to its first element.
Why are all pointer types the same size?
Because they store memory addresses, which have a fixed size on a given architecture.
What is pointer indirection?
Accessing the value at a memory address stored in a pointer using the * operator.
What is a dangling pointer?
A pointer that points to memory that has been freed or is no longer valid.
How can you avoid buffer overflow with strings?
By using functions like strncpy() instead of strcpy() and ensuring proper bounds checking.
What does realloc() do?
It resizes previously allocated memory, copying existing contents to a new location if needed.
What is the difference between shallow copy and deep copy?
A shallow copy copies memory addresses, while a deep copy duplicates the actual data.
How do you write a struct to a file?
Using fwrite() to write binary data directly to a file.
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.
What is the purpose of sign extension?
To correctly extend the sign bit when converting a smaller signed value to a larger type.
What does the term 'word size' mean in computing?
The number of bits a CPU processes at a time, typically 32 or 64 bits.
How does the right shift (>>) operator behave?
It shifts bits to the right, dividing the number by 2 for each shift.
What is a circular shift?
A shift operation where bits that are shifted out are reintroduced on the opposite side.
What happens if an unsigned integer overflows?
It wraps around to 0 and continues from there.
What is the largest positive value a signed 8-bit integer can hold?
127 (01111111 in binary).