1/20
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What does it mean that C gives direct access to memory?
C allows direct manipulation of memory using pointers, and every memory byte has a unique address.
How does C's memory management differ from higher-level languages like Java?
C requires manual memory management, unlike Java which uses automatic garbage collection.
What is the purpose of memory protection by the OS?
It prevents crashes from invalid memory access by isolating memory spaces.
What is a variable in C?
An abstraction for a memory location used to store data.
What does int h2g2 = 42;
do in memory?
Allocates 4 bytes and stores the value 42.
How do you get the memory address of a variable in C?
Use the address-of operator: &variable
.
What is the difference between declaration and definition in C?
Declaration introduces a name and type; definition allocates memory.
What value might an uninitialized variable contain?
Garbage (undefined/random value).
How does C handle function arguments by default?
By value — the function receives a copy of the argument.
How do you modify a variable inside a function in C?
Pass its address using a pointer and dereference it inside the function.
What does a pointer store?
The memory address of another variable.
How do you get the value a pointer points to?
Dereference it using *pointer
What is a pointer to a pointer?
A variable that stores the address of another pointer, e.g., int **pp
.
How is an array represented in memory in C?
As a contiguous block of memory, with the array name pointing to the first element.
How does pointer arithmetic work with arrays?
arr[i]
is equivalent to *(arr + i)
What happens when you cast an array to another pointer type, like (char*)arr
?
You can access the memory byte by byte, but incorrect casting may misalign data.
How are strings represented in C?
As null-terminated character arrays (char[]
ending with \0
).
What does %s
in printf
expect?
A char*
to a null-terminated string
How do you modify a variable using a function and pointers?
Pass the variable's address:
void change(int *p) { *p = 7; }
change(&x);
When a pointer is passed to a function, what actually gets passed?
A copy of the address (pass-by-value still applies).
Why shouldn't you return a pointer to a local variable?
Because the variable’s memory is deallocated after the function ends, making the pointer invalid.