Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Pointer exercise for C as a second programming language.

Notifications You must be signed in to change notification settings

jreiser1/c-pointer-exercises

 
 

Repository files navigation

C Pointer Exercises

In-class C pointer exercises. If not finished, will be due as homework.

Arrays

Static arrays

Global array

  1. Define a structure.
  2. Declare a static array of structures, outside of any function. What is the type of the array variable?
  3. Sketch the array on the worksheet.
  4. Assign values in a loop.
  5. Step through the code with the debugger.

Local array

  1. Define a structure.
  2. Declare a static array of structures, inside a function. What is the type of the array variable?
  3. Sketch the array on the worksheet.
  4. Assign values in a loop.
  5. Step through the code with the debugger.
Sketch

Static array (global or local)

Dynamic arrays

Monolithic array

  1. Define a structure.
  2. Allocate a dynamic array of structures. What is the type of the array variable?
  3. Sketch the array on the worksheet.
  4. Assign values in a loop.
  5. Free all dynamic memory.
  6. Step through the code with the debugger.
Sketch

Dynamic monolithic array

Array of pointers

  1. Define a structure.
  2. Allocate a dynamic array of pointers to structures. What is the type of the array variable?
  3. Sketch the array on the worksheet.
  4. Assign values in a loop.
  5. Free all dynamic memory. Mind the order to avoid leaving dangling pointers!
  6. Step through the code with the debugger.
Sketch

Dynamic array of pointers

Linked lists

  1. Declare a node structure for a singly-linked list, holding a single int value.
  2. Declare the list's head and tail pointers.
  3. Initialize the linked list. What does an empty list look like?
  4. Reason out the different assignment cases for the list_insert function. The nodes have to be inserted in ascending order. How should the pointer member of the node structure be initialized by default?
  5. Implement the list_insert function, for all cases you came up with.
  6. Test the function for all the cases. Run in the debugger to see if it works. Correct it.
Sketch

Singly-linked list

About

Pointer exercise for C as a second programming language.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 96.5%
  • CMake 3.5%