Why is this happening? This seems like a very normal thing to do.Code:char * seq = "1234567890";
Why is this happening? This seems like a very normal thing to do.Code:char * seq = "1234567890";
That works. Also, I found char seq[] = "1234567890"; worked too.
The reason is that "1234567890" creates a string constant somewhere in memory. It cannot be modified in any way. So any pointer to it should explicitly be said to be a pointer to a constant.
char seq[] = "1234567890" is a bit of an abuse of notation; it is shorthand for
which is a perfectly legitimate array initialization.Code:char seq[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' }
Code:while(!asleep) { sheep++; }
i want to say ,my program is all normal
Actually, it is shorthand for:Originally Posted by TheBigH
I don't see why it would be "a bit of an abuse of notation".Code:char seq[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0' '\0'}
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
yeah ! #6 is right !
IMHO it is not the least bit abuse.
It's no different to me than using a += b; instead of a = a + b; is. It's just two different ways of representing the same thing.
In fact the shorter, more concise option is definitely the preferred option.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"