Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

pointer in return function c++

#include <iostream>

using namespace std;

int *getDouble(int* x){
    int *result = new int ((*x) * 2);		// save the result in the heap
    return result;    	//return the address of the result
}

int main(){
    int x=5;
    int *ptr = getDouble(&x);		//the pointer points to the result address
    cout<<*ptr<<endl;
}
 
PREVIOUS NEXT
Tagged: #pointer #return #function
ADD COMMENT
Topic
Name
9+9 =