I am a new student in programming, so please forgive my ignorance. My destination states:
Write a program declaring an array of 10 integers. Write a loop that takes 10 values ββfrom the keyboard and write another loop that displays 10 values. Do not use indexes inside two loops; use pointers only.
Here is my code:
#include "stdafx.h" #include <iostream> using namespace std; int main() { const int NUM = 10; int values[NUM]; int *p = &values[0]; int x; for(x = 0; x < NUM; ++x, ++p) { cout << "Enter a value: "; cin >> *p; } for(x = 0; x < NUM; ++x, ++p) { cout << *p << " "; } return 0; }
I think I know where my problem is. After my first loop, my pointer has the values ββ[10], but I need to return it to the values ββ[0] to display them. How can i do this?
c ++ pointers
talena6
source share