Pointers, Dynamic Memory, Linked Lists, and File I/O Flashcards

(40 cards)

1
Q

What is pointer arithmetic?

A

Performing arithmetic operations on pointers.

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

Fill in the blank: A void pointer (void *) is a _______.

A

Generic pointer that can store addresses of any data type.

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

What function is used for dynamic memory allocation?

A

malloc()

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

What should you always check after using malloc()?

A

If malloc() succeeds.

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

What function is used to release allocated memory?

A

free()

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

What are common pitfalls related to pointers?

A
  • Memory Leaks
  • Dangling Pointers
  • Wild Pointers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a segmentation fault?

A

Occurs when trying to access memory illegally.

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

What tool can be used for memory debugging?

A

valgrind

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

True or False: Pointer arithmetic follows the size of the data type.

A

True.

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

What happens if you forget to free memory?

A

Memory leaks occur.

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

What is a dangling pointer?

A

Using a pointer after the memory it points to has been freed.

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

What is a wild pointer?

A

Using uninitialized pointers.

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

What does p++ do if p is a pointer to an int?

A

Moves p to the next int (increases by sizeof(int)).

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

What happens when you write beyond allocated space?

A

It can corrupt adjacent memory.

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

What is the output of printf(“p = %p, *p = %c\n”, p, *p) if p points to ‘A’?

A

p= 0x1e224eff, *p= A

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

Fill in the blank: The function _______ is used to allocate memory for an array of integers.

A

malloc()

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

What is Pass by Value?

A

A copy of the variable is passed to the function, keeping the original variable unchanged.

18
Q

What is a downside of Pass by Value?

A

Can be inefficient for large data structures.

19
Q

How does Pass by Reference work?

A

A pointer to the variable is passed instead of a copy, allowing the original variable to be modified.

20
Q

What is a pointer in C?

A

A pointer stores the memory address of another variable.

21
Q

What is the syntax to dereference a pointer?

A

Using the asterisk (*) before the pointer variable.

22
Q

What is a function pointer?

A

A function pointer stores the address of a function.

23
Q

Why use function pointers?

A

Makes code modular and reusable; enables dynamic function execution.

24
Q

What is a key advantage of linked lists over arrays?

A

They do not need a predefined size and allow efficient insertions and deletions.

25
What is the basic structure of a linked list node?
struct Node { int data; struct Node *next; };
26
How do you insert a node at the beginning of a linked list?
Create a new node, set its next to the current head, and update the head to the new node.
27
What is the purpose of the printList function?
To traverse and print all the nodes in the linked list.
28
True or False: Pass by reference allows modifying original values.
True.
29
Fill in the blank: _______ enables dynamic execution of functions.
Function pointers.
30
Final takeaway: What do linked lists provide compared to arrays?
More flexibility for dynamic data storage.
31
What is the purpose of scanf() in C?
Takes user input.
32
What does scanf() return?
Number of values successfully assigned.
33
What happens if input fails in scanf()?
Exits the loop.
34
Define a stream in the context of programming.
A way of handling data flow in a program.
35
What are the key features of a stream?
* Abstracts file handling * Buffered * Two types: Text Streams and Binary Streams
36
What is the function to open a file in C?
fopen()
37
What is the function to close a file in C?
fclose()
38
What does a file pointer (FILE *) do?
Accesses files in C.
39
What does fopen() return if it fails?
NULL
40
What mode is used to open a text file for reading?
"r"