Im very new, what does this mean when a * is in this location
char* val;
I noticed its used here Cprogramming.com Tutorial: Pointers however it is applied to the val and not char
char *val;
Im very new, what does this mean when a * is in this location
char* val;
I noticed its used here Cprogramming.com Tutorial: Pointers however it is applied to the val and not char
char *val;
It is attached to the variable.If it attached to 'char', then both 'ptr' and 'notaptr' would be pointers, but it attaches to 'ptr'. The result is that 'notaptr' is just a char. To make them both pointers, you would need:Code:char *ptr, notaptr;The easy thing to do is to read from right to left:Code:char *ptr, *aptr;ptr is a...Code:char *ptr;
* pointer to a...
char
Quzah.
Hope is the first step on the road to disappointment.
char* val
char *val
are both char pointers, i.e., they point to some char in the heap. The beginning char of a string for instance.
Ah, I misunderstood the question. The whitespace is irrelevant. These are all the same:Good catch.Code:char* p; char *p; char * p; char*p;
Quzah.
Hope is the first step on the road to disappointment.
so
char* bla1, bla2, bla3;
means all the bla1..2..3 are all now pointers?
or it means just bla1 would be a pointer and bla2..3 are chars?
---
and
struct val1 * val2;
means just val2 is a pointer?
Last edited by starternewb; 03-14-2011 at 09:58 PM.
Read my first reply. Only bla1 is a pointer, the other two are not.
Quzah.
Hope is the first step on the road to disappointment.
No... only the one with the star.
It is true that whitespace doesn't matter however I find the line you have to be visually deceiving since, gramatically, it seems to say 3 pointers. Which is why I put the * with the variable... for me, it's clearer.
To make all three ponters you need...
Code:char *bla1, *bla2, *bla3;Yes, val2 is a pointer to a struct of type val1.struct val1 * val2;
means just val2 is a pointer?
wahoo, thanks everyone for the help much appreciated!