Question: 1. Write a single C++ programming statement that will define a pointer variable named iptr that is capable of pointing to an integer variable. 2.
1. Write a single C++ programming statement that will define a pointer variable named iptr that is capable of pointing to an integer variable.
2. Write a single C++ programming statement that will define a pointer variable named dptr that is capable of pointing to a double variable and initialized to the value nullptr.
3. Given the following C++ code:
int numbers[] = {11, 22, 33, 44, 55, 66};
int *numPtr = nullptr;
Write the C++ statement(s) that will make the pointer variable named numPtr point to the third element in the array called numbers.
4. You are given a C++ pointer to the double data type, which contains the memory address value 1010. If the integer value four (4) is added to this pointer, what will be the value of the pointer if the double data type occupies 8 bytes in memory? (You may assume the address is expressed as a decimal value.)
5. Write the C++ programming statements necessary to create an int pointer named intPtr and use it to dynamically allocate storage for a 42- element array of integers.
Programming Exercise:
Write a C++ program that prompts the user for the size of a double array. The program will dynamically allocate a double array large enough to hold the user-defined number of double values. Next, your program will prompt the user to enter all the values in the array. After all the values have been entered, the array should be passed to a function that calculates the average value and returns it as a double. Your program will then display the number of values and the average value.
Use pointer notation rather than array notation whenever possible. Include input validation in your program that requires the user to re-enter negative values should they be entered as array element values.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
