PLEASE TRACE BY HAND OR EXPLAIN WHAT EACH VALUE IS ASSIGNED TO /* SELECT the CODE SEGMENT that will use the pointer variable p to set all elements of the array to zero. (Note: ONLY POINTER NOTATION CAN BE USED TO ANSWER THIS QUESTION.) */ #include using namespace std; int main() { int array[25]; int *p, i; // (a) for (i = 0; i < 25; i++) { array[i] = 0; } // (b) p = &array[0]; for (i = 0; i < 25; i++) { *p = 0; } // (c) p = array; for (i = 0; i < 25; i++) { array[i] = 0; } // (d) i = 0; for (p = &array[0]; p < &array[0] + 25; p++) { *p = 0; } cout << endl << "That's all there is!"; system("Pause"); return 0; } //end main
PLEASE TRACE BY HAND OR EXPLAIN WHAT EACH VALUE IS ASSIGNED TO
/* SELECT the CODE SEGMENT that will use the pointer variable p to set all elements of the array to zero. (Note: ONLY POINTER NOTATION CAN BE USED TO ANSWER THIS QUESTION.) */
#include <iostream>
using namespace std;
int main()
{
int array[25];
int *p, i;
// (a)
for (i = 0; i < 25; i++)
{
array[i] = 0;
}
// (b)
p = &array[0];
for (i = 0; i < 25; i++)
{
*p = 0;
}
// (c)
p = array;
for (i = 0; i < 25; i++)
{
array[i] = 0;
}
// (d)
i = 0;
for (p = &array[0]; p < &array[0] + 25; p++)
{
*p = 0;
}
cout << endl << "That's all there is!";
system("Pause");
return 0;
} //end main
Step by step
Solved in 2 steps