what arithmetic can you do with pointers? addition, subtraction, multiplication?
If you assign a 0 to a pointer would it make the pointer point to nothing?
Printable View
what arithmetic can you do with pointers? addition, subtraction, multiplication?
If you assign a 0 to a pointer would it make the pointer point to nothing?
>what arithmetic can you do with pointers?
You can add or subtract by an integer, or subtract by a pointer. All of these are only strictly defined for pointers into an array or simulated array.
>If you assign a 0 to a pointer would it make the pointer point to nothing?
Close enough, yes. :)
can a pointer variable store the address of another variable?
does an array's name store the address of the array's first element?
Is an array's name a pointer, constant, and a variable?
>can a pointer variable store the address of another variable?
Yes:
x now points to the memory address of a.Code:int a;
int *x=&a;
>does an array's name store the address of the array's first element?
I always answer this wrong, so I'm not going to embarass myself.
>Is an array's name a pointer, constant, and a variable?
See above. :)
The array's name is a pointer to the first (0th) element. The subscript simply adds that value to the base address (the first element of the array). For some fun, try the following (and you'll see what I mean):
*edit*Code:int array[4] = { 1, 2, 4, 8 };
std::cout << array[3] << std::endl;
std::cout << 3[array] << std::endl;
I hope no one saw that. :cool:
>can a pointer variable store the address of another variable?
That's really the definition of a pointer, isn't it?
>does an array's name store the address of the array's first element?
No, but in most cases the name of an array is converted to a pointer to the first element.
>Is an array's name a pointer, constant, and a variable?
No, somewhat, and yes. Contradictory, no? ;) Try this on for size.