void func( int* pointer){
int i = 0 ;
std::cout << *(pointer+i) ; // list[i]
};
int list[]={1,2,3,9};
int* pointer = list ;
func(pointer);
#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;
}
}
int *ptr;
int arr[5];
// store the address of the first
// element of arr in ptr
ptr = arr;
Code Example |
---|
Cpp :: passing custom function in sort cpp |
Cpp :: c++ constructor call superclass |
Cpp :: variables in c++ |
Cpp :: do while c++ |
Cpp :: c++ insert variable into string |
Cpp :: linked list cycle c++ |
Cpp :: selection sort c++ |
Cpp :: put text on oled |
Cpp :: c++ fonksion pointer |
Cpp :: set of vectors c++ |
Cpp :: sum of first 100 natural numbers |
Cpp :: glm has no member value_ptr |
Cpp :: vector<intv[] |
Cpp :: matrix c++ |
Cpp :: find the graph is minimal spanig tree or not |
Cpp :: how to print items in c++ |
Cpp :: nullptr c++ |
Cpp :: Character cin(userInput) in c++ |
Cpp :: assignment operator with pointers c++ |
Cpp :: how to find factorial of number in c++ |
Cpp :: string c++ |
Cpp :: find factorial in c++ using class |
Cpp :: c++ pass function as argument |
Cpp :: assign value to a pointer |
Cpp :: operator overloading c++ |
Cpp :: auto in cpp |
Cpp :: fname from FString |
Cpp :: heapsort |
Cpp :: Vaccine Dates codechef solution in c++ |
Cpp :: cplusplusbtutotrail |