Little doubts
-
i got some small doubts as i am new to c++. Will u please help me to sort it out? (1)is 'int* x' same as 'int *x' (2)'char const* x' same as ‘const char *x’ Vendy
-
i got some small doubts as i am new to c++. Will u please help me to sort it out? (1)is 'int* x' same as 'int *x' (2)'char const* x' same as ‘const char *x’ Vendy
1 - yes, whitespace is irrelevant 2 - no. one makes the pointer const, one makes it's contents const, from memory. They are not the same tho. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
i got some small doubts as i am new to c++. Will u please help me to sort it out? (1)is 'int* x' same as 'int *x' (2)'char const* x' same as ‘const char *x’ Vendy
-c wrote: (1)is 'int* x' same as 'int *x' it works the same, but some people prefer one over the other to remind them it is a pointer to int, not int pointer. -c wrote: (2)'char const* x' same as ‘const char *x’ char const * x;//this is a constant pointer to a char type const char * x;//this is a pointer to a constant char type
-
i got some small doubts as i am new to c++. Will u please help me to sort it out? (1)is 'int* x' same as 'int *x' (2)'char const* x' same as ‘const char *x’ Vendy
(1)
int* x
andint *x
mean the same thing. (2)char const* x
andconst char *x
do not mean the same thing.char const* x
may be read as 'x is a constant pointer to char'. In this case, the pointer is constant, not the character data it points to.const char *x
may be read as 'x is a pointer to characters that are constant.' For this one, the character data is constant.
Software Zen:
delete this;
-
-c wrote: (1)is 'int* x' same as 'int *x' it works the same, but some people prefer one over the other to remind them it is a pointer to int, not int pointer. -c wrote: (2)'char const* x' same as ‘const char *x’ char const * x;//this is a constant pointer to a char type const char * x;//this is a pointer to a constant char type
thank you guys.... one more thing.. is 'char const*' same as 'char *const'??? Vendy
-
thank you guys.... one more thing.. is 'char const*' same as 'char *const'??? Vendy
yes. const is only an identifier, but most use it before the type. you could verify it by yourself (and you will have too because even if you're new to VC++, this is not a "primary school forum") using
sizeof()
... another thing : read this[^]
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
1 - yes, whitespace is irrelevant 2 - no. one makes the pointer const, one makes it's contents const, from memory. They are not the same tho. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
I think you got it wrong, char const * x and const char *x are the same and prevent you from changing the contents. For making the pointer itself const, you need to use char * const x. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
(1)
int* x
andint *x
mean the same thing. (2)char const* x
andconst char *x
do not mean the same thing.char const* x
may be read as 'x is a constant pointer to char'. In this case, the pointer is constant, not the character data it points to.const char *x
may be read as 'x is a pointer to characters that are constant.' For this one, the character data is constant.
Software Zen:
delete this;
char const* x and const char *x are the same thing, and they mean "x is a pointer to characters that are constant.'". "char * const x" means "x is a constant pointer to char"
-
yes. const is only an identifier, but most use it before the type. you could verify it by yourself (and you will have too because even if you're new to VC++, this is not a "primary school forum") using
sizeof()
... another thing : read this[^]
TOXCCT >>> GEII power
[toxcct][VisualCalc]toxcct wrote: read this[^] Bad link, perhaps?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
i got some small doubts as i am new to c++. Will u please help me to sort it out? (1)is 'int* x' same as 'int *x' (2)'char const* x' same as ‘const char *x’ Vendy
-c wrote: (2)'char const* x' same as ‘const char *x’ See here.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow