difference between int* i and int *i

Viewed 25254

I'm converting a header file for a DLL written in C to Delphi so I can use the DLL.

My question is what is the difference between

int* i

and

int *i

I convert the first to

i: PInteger;

But i'm not sure what the correct conversion is for the second one in Delphi.

from my understanding the first is a simple typed pointer. The second is a pointer variable. but i'm not sure what the difference is.

9 Answers

It is different as:

  1. When you want to declare many pointers on one line without writing * every time then you can use int* a,b,c,d; Here, a,b,c,d will all be pointers to integer

  2. When you want to declare a pointer and a normal variable in one line, you must use int *a,*b,c,d; Here, a and b are pointers to integer, c and d are integer variables.

Points mentioned above highlight cases where "Type *" makes the most sense.

But a case where I personally found "Type*" makes intuitive sense/is more readable is when passing a reference to a pointer type. It is non-intuitive to a beginner when reading a variable as :

int *&x; // what is x here ?

as opposed to :

int* (&x); // A reference to a int* type

Related