Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


getResponse autofunnels

Liquid Web Cloud VPS Hosting

11,407 questions

15,557 answers

573 users

How to use pointer to int array in C++

1 Answer

0 votes
#include <iostream>

int main() {  
    int arr[5] = {1, 2, 3, 4, 5};
    
    int *p = &arr[0];  

    std::cout << "1 *p = " << *p << std::endl;
    std::cout << "2 arr[0] = " << arr[0] << std::endl;
    
    std::cout << "3 *++p = " << *++p << std::endl;
    std::cout << "4 arr[1] = " << arr[1] << std::endl; 
    
    std::cout << "5 *p = " << *p << std::endl;
    std::cout << "6 arr[1] = " << arr[1] << std::endl; 
    
    *(p + 2) = 99;
    std::cout << "7 *(p + 2) = " << *(p + 2) << std::endl;
    std::cout << "8 arr[3] = " << arr[3] << std::endl;  
    
    *p++;
    std::cout << "9 *p = " << *p << std::endl;
    std::cout << "10 arr[2] = " << arr[2] << std::endl;  
    
    return 0;  
}  




/*
run:

1 *p = 1
2 arr[0] = 1
3 *++p = 2
4 arr[1] = 2
5 *p = 2
6 arr[1] = 2
7 *(p + 2) = 99
8 arr[3] = 99
9 *p = 3
10 arr[2] = 3

*/

 




answered Oct 6 by avibootz
edited Oct 6 by avibootz
...