Pointers in c language: 17 flashcards

All 17 flashcards from this kit, free and with no sign-up.

1. What is a pointer in C?

Show the answer

A pointer is a variable that stores the memory address of another variable.

2. How do you declare a pointer to an integer?

Show the answer

`int *ptr;`

3. What does the address-of operator (&) do?

Show the answer

It returns the memory address of a variable. For example, `&x` gives the address of `x`.

4. What does the dereference operator (*) do when used with a pointer?

Show the answer

It accesses the value stored at the memory address held by the pointer. For example, `*ptr` gives the value at the address `ptr` points to.

5. Given `int x = 10; int *p = &x;` What is the value of `*p`?

Show the answer

`*p` is 10, because `p` points to `x` and dereferencing `p` gives the value of `x`.

6. What is a NULL pointer?

Show the answer

A pointer that is assigned the value `NULL` (or 0) to indicate that it does not point to any valid memory location.

7. Why is it important to initialize a pointer to NULL?

Show the answer

To avoid undefined behavior from using an uninitialized pointer, which may point to an arbitrary memory location.

8. What is pointer arithmetic?

Show the answer

Performing arithmetic operations (like addition or subtraction) on pointers. The result is scaled by the size of the data type the pointer points to.

9. If `int arr[5]` and `int *p = arr;` What does `p + 2` point to?

Show the answer

It points to `arr[2]`, because `p + 2` advances by 2 integers (i.e., 2 * sizeof(int) bytes).

10. What is the relationship between arrays and pointers in C?

Show the answer

An array name acts as a pointer to its first element. For example, `arr` is equivalent to `&arr[0]`.

11. How do you pass a pointer to a function to modify a variable?

Show the answer

Pass the address of the variable using `&` and accept it as a pointer parameter. For example: `void func(int *p) { *p = 20; }` and call `func(&x);`.

12. What is a pointer to a pointer?

Show the answer

A pointer that stores the address of another pointer. Declared as `int **ptr;`.

13. Given `int x = 5; int *p = &x; int **pp = &p;` What is `**pp`?

Show the answer

`**pp` is 5, because `pp` points to `p`, and `p` points to `x`, so dereferencing twice gives the value of `x`.

14. What is a void pointer (`void *`)?

Show the answer

A generic pointer that can hold the address of any data type, but cannot be dereferenced directly without casting.

15. How do you dynamically allocate memory for an integer using `malloc`?

Show the answer

`int *p = (int *)malloc(sizeof(int));`

16. What is a dangling pointer?

Show the answer

A pointer that points to a memory location that has been freed or deallocated. Using it leads to undefined behavior.

17. What is the difference between `p` and `&p` when `p` is a pointer?

Show the answer

`p` is the address stored in the pointer (the address of the variable it points to). `&p` is the address of the pointer variable itself.

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Exam prep

Get Veda free See what students get

Free to start · No ads · Works in 42 languages