pointer_array.cpp 711 B

12345678910111213141516171819202122232425262728
  1. #include <iostream>
  2. int main()
  3. {
  4. int my_array[5] = {1, 2, 3, 19, 5};
  5. // same 2 line
  6. std::cout << " Add: " << my_array << std::endl;
  7. std::cout << " Add: " << &my_array << std::endl;
  8. std::cout << "Add+3: " << my_array + 3 << std::endl;
  9. std::cout << *(my_array + 3) << std::endl;
  10. // this line below is doing exactly the same as the line above
  11. std::cout << my_array[4] << std::endl;
  12. int new_array[5];
  13. for (int i = 0; i < 5; i++)
  14. {
  15. std::cout << "Number: ";
  16. std::cin >> new_array[i];
  17. }
  18. // care the index number if using this method
  19. for (int i = 0; i < 6; i++)
  20. {
  21. std::cout << *(new_array + i) << std::endl;
  22. }
  23. return 0;
  24. }