*int var Vs. int *var

I'm not sure how many articles there have been about this in particular, but I feel like this is something which should be touched upon regardless.

I have no idea what the difference between referencing *int var = 3 is, as opposed to int *var = 3.

Does *int refer to an array?
Holland wrote:
I have no idea what the difference between referencing *int var = 3 is, as opposed to int *var = 3.


Me neither. The first variant does not appear to be valid code. I don't see how you can put a * before the typename so I don't understand the question. Please rephrase the question and post an example that compiles.
Agreed. The first form is not valid C++ AFAIK. Where did you get it from?
While the first should be a compiler error, the second isn't particularly useful either. Here's what I assume was meant:
1
2
3
4
5
6
7
8
9
int n = 1;

// second snippet:

int* p = &n; // assign an address to the pointer, not just some number

// first snippet:

*p = 2;


The tutorial should cover both cases.
Topic archived. No new replies allowed.