Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In c complete the following code using only POINTER ARITHMETIC method: /* Purpose: Array traversal by POINTER ARITHMETIC ======================================= Program Description: This program populates 1D
In c complete the following code using only POINTER ARITHMETIC method:
/* Purpose: Array traversal by "POINTER ARITHMETIC" ======================================= Program Description: This program populates 1D integers arrays with integer values. The "values" 1D array is populated with consecutive integer values in the range [1 to 10]. The "squares" 1D array is populated with the corresponding square values. This version of the program access these two arrays by using the POINTER ARITHMETIC method. */ #include #include #define MAX_SIZE 10 int main(int argc, char *argv[]) { //============================== setbuf(stdout, NULL); // turns standard output buffering off int i; // Loop counter/index. int values [MAX_SIZE]; // Integer Array of size 10. long int squares[MAX_SIZE]; // integer Array of size 10. int *pV; // Integer Pointer. long int *pS; // Long Integer Pointer. pV = values; // or: pV = &values[0]; Set pV to point to first element of array "values". pS = squares; // or: pS = &squares[0]; Set pS to point to first element of array "squares". // === NOTE: From this point on, to the end of the program, you are NOT allowed // === to use or write the "values" or "squares" array names. // === You must reference these arrays ONLY by using the respective pointers "pV" and "pS". // Populate the "values" array with consecutive integers // [1,2,3, ..., 10] { // Populate each element of the "squares" array with the // square value of its corresponding integer value stored in // the "values" array. // Print the table of values printf(" "); printf("Array traversal by \"POINTER INDEXING\" "); printf("===================================== "); printf(" "); printf("Value Square "); printf("===== ========== "); printf("::: "); printf("::: Program Terminated. "); printf("::: "); return 0; }
output must look like this:
Array traversal by "POINTER ARITHMETIC" Value Square ===== ========= 12345678910149162536496481100 :: : : : Program Terminated
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started