Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ pointers and functions

#include <iostream>

using namespace std;

void increment(int *n){  		//declare argument of the functon as pointer
    *n+=1;
   cout<<"In function: "<<*n<<endl; 
}

int main()
{
   int x=5;			
   increment(&x);		//passing the address of the variable to the function
   cout<<"In main: "<<x<<endl;
   
}
Source by www3.ntu.edu.sg #
 
PREVIOUS NEXT
Tagged: #pointers #functions
ADD COMMENT
Topic
Name
2+2 =