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:
ptr=arr;
- Define a function for calculating the average of the array elements. A pointer to an array and the count of the number of values in the array are both passed to this function:
average=findaverage(ptr, count);
- In the function, define an assert expression that ensures that the pointer is not NULL. If the pointer is NULL, the program will display an error and will be aborted:
assert(Ptr != NULL && "Pointer is not pointing to any array");
- If the pointer ...