I'm starting to study C++. I ran into a small confusion regarding pointers, specifically a NULL pointer. From my understanding when you declare a pointer and you set it to point to a value you can do the following:
int var = 10; int *ptr; ptr = &var; *ptr = 20; This would change the value of var to 20. But when you set a NULL pointer you do the following:
int *ptr = NULL; Doesn't this mean you're assigning the value NULL to whatever variable ptr is pointing to not the address, because of the * operator? I thought a NULL pointer has a value (its address) as 0 so it points nowhere, from what I read. Would it make more sense to do this:
int *ptr; ptr = NULL // or 0? An explanation in layman terms would be appreciated, I'm still learning all the terms as I code and research so I'd love an explanation of any programming terms you use.
int * ptr = &var. In this case*is not an operator, is just part of the type.int* ptrinstead ofint *ptr.int* ptr, a;becomes confusing, isaa pointer? whileint *ptr, a;it is pretty clear that it is not.int *ptr = NULL;is just short-hand forint *ptr; ptr = NULL;