Let's perform one more recipe on assertions. Let's apply assertions to ensure that a pointer is not pointing to NULL and is instead pointing to a memory address that is to be accessed. Essentially, in this recipe, we will learn to compute the average of a few numbers, where the numbers are stored in an array, and the array elements are accessed through a pointer.
Using assertions to ensure a pointer is not pointing to NULL
How to do it…
Follow these steps to ensure that the pointer is not NULL and is pointing to a memory address by making use of assertions:
- Define an array containing a number of integers whose average is to be computed:
int arr[]={3,9,1,6,2};
- Set a pointer to point to the array...