GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Sunday, December 19, 2010

Pointer As Function Argument

What it means? It means that the argument will hold address of input. So what the value in pointer in the function, it will directly will affect variable arguments.

#include <iostream>

int areaCalc(int*);

int main(){

    int width = 4;
    int area = width * width;
    cout << "Area (manual calc): " << area << endl;

    int area_from_func = areaCalc(&width); 
    cout << "Area (func calc): " << area_from_func << endl;

    return 0;
}

int areaCalc(int* width_address){
    int area = (*width_address) * (*width_address);
    return area;
}
Share/Bookmark

No comments:

Post a Comment