Search code examples
c++terminology

Function has parameter of type `int`, but gets passed an argument of type `int*`


I have a question about terminology. Consider a unary function. I read in this thread that the function's parameter is the 'variable' used in its declaration, and the 'argument' is the actual value of the variable one passes to the function when calling it. However, consider this simple function:

void f(int *p){};

It has one parameter *p of type int. However, when calling the function I can do

v = 25;
int* w = &v;
f(w);

I.e., I pass an argument of type int* to the function, which means I'm passing an argument of a different type than the parameter.

I'm thinking of a function as a map f:A->B whose domain A determines the type of both parameter and argument, i.e. they should be equal. What is wrong with my reasoning?


Solution

  • Your function has one parameter p of type int*. You pass it one argument w of type int*. The placement of the * causes some awkwardness at the syntactic level, but for type checking purposes you should regard it as part of the type.