Quick query about (surprise!) pointers
I realize this may have been answered thousands of times already, but after some quick searching through archives I was unable to find the answer I was looking for.
I'm reading through a "Teach Yourself C in 21 Days" book (published '97), basically so I have a comprehensive learning experience in learning C++ and C#.
It says, and I quote:
The very next question is:
So, if the question isn't obvious...
Is *string1 really == string1, or is the book lying to me?
In both declarations ('char *string1' vs 'char string1'), 'string1 == &string1' regardless, right? ...right?
So how are they different?
I feel like I'm taking crazy pills...
Re: Quick query about (surprise!) pointers
You cannot declare an empty array. You may declare what LOOKS like an empty array, if you initialize it, as in
char string  = "This is a string";
That's a favor to you, from the compiler; the compiler can count the number of element that will be required.
*string and string  are equivalent and either may be used as an argument to a function. A pointer to an array and the name of the array are equivalent, but not the same. The standard requires that there be a means of converting from an array name to a pointer to the first element of that array. If you use an array name and if you use a pointer to an array, then examine the emitted machine code, you will see that there is one level of indirection difference. The compiler has provided that for you, pursuant to the requirements of the standard.
I would suggest that you read the pointer tutorial referenced in my signature. It touches on that equivalency, but non-equality.
|All times are GMT +5.5. The time now is 15:26.|