Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ array pointer

void func( int* pointer){
  int i = 0 ;
  std::cout << *(pointer+i) ; // list[i]
};

int list[]={1,2,3,9};
int* pointer = list ;
func(pointer);
Comment

pointers and arrays in c++

#include <iostream>

using namespace std;

int main()
{
    int x[3] = { 5,9,20 };
    int* p = x;
    cout << p << endl;               //prints the address of x[0]
    cout << *p << endl;             //prints the value of x[0] (5)
    //printing the array
    for (int i = 0; i < 3; i++){
        cout << p[i] << endl;
        //or
        cout << *(p + i) << endl;
    }

}
Comment

C++ Pointers and Arrays

int *ptr;
int arr[5];

// store the address of the first
// element of arr in ptr
ptr = arr;
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to access a vector member by its index 
Cpp :: c++ string_t to string 
Cpp :: max pooling in c++ 
Cpp :: constrain function in arduino 
Cpp :: cpp oop 
Cpp :: program to swap max and min in matrix 
Cpp :: min heap stl 
Cpp :: full implementation of binary search tree in C++ 
Cpp :: char array declaration c++ 
Cpp :: accumulate in cpp 
Cpp :: potato 
Cpp :: c++ add input in 
Cpp :: lists occurrences of characters in the string c++ 
Cpp :: c++ split string 
Cpp :: assign one vector to another c++ 
Cpp :: async multi thread 
Cpp :: c++ write string 
Cpp :: round c++ 
Cpp :: for_each c++ 
Cpp :: valid parentheses in c++ 
Cpp :: dynamic memory in c++ 
Cpp :: c++ structs 
Cpp :: c++ stl 
Cpp :: cuda shared array 
Cpp :: recherche recursive le max dans une liste 
Cpp :: faster solutions 
Cpp :: time_t c++ stack overflow 
Cpp :: nmake.exe is not found in the windows 
Cpp :: c++ restrict template types 
Cpp :: c++ if 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =