Array Concept. . . .

Pages: 123
@htirwin

Because sizeof gets you how much memory, not how many items


a_sizeof( n ) is not the same as sizeof( n )
One more look the function definition.
1
2
computerquip
EDIT: I could have sworn there was some funky syntax that allowed you to use pointer syntax to initialize arrays... maybe that was an old GCC extension.


there was?. What do you mean ? Are you rtying to say that there WAS Something like this and now is disclosed? I don't think so i am studying a book which is INTERNATIONALLY reputed about C++ in which all this has been told . Even latest version probably 9th Version published after 2010 is saying arrays are pointers. Why all of you are not accepting?

Moreover i have given you the answer to your question sizeof() operator. Why don't you all check that?

to answer this read this:

sizeof() : When applied to a reference type, the result is the size of the referenced type
i.e. when applied to POINTER which is referenced DIRECTLY

and

when applied to array gives the size of whole array in bytes becox it has not been referenced DIRECTLY but pointer does have. You can access every element of array just becox it's first element and it's ADDRESS in which you increment to get next elements.


LINK :http://en.cppreference.com/w/cpp/language/sizeof
1
2
3
4
5
6
7
And I do not know why you are showing this quote/ What does it prove?! I showed you already that results of sizeof for an array and a pointer are different

Moreover for an array you can calculate the number of its elements the following way

sizeof( array ) / sizeof( *array )

For any pointer this formula gives you an incorrect result.



Please read my above POST . Thank you! You're not even understanding what i am trying to say!
1
2
3
cire:

Arrays are not pointers. Pointers are not references.


then what's array? a collection of memory for the same datatype?. Yeah fine i agree then how do you access array elements individually? by doing this:

array[0], array[1],array[2],. . . . ?

yeah also by memory. Same post already has been posted you can check it too.


http://www.cplusplus.com/forum/articles/10/


Moreover do check the last comment by Graham
Ahmad1718 wrote:
sizeof() : When applied to a reference type, the result is the size of the referenced type
i.e. when applied to POINTER which is referenced DIRECTLY

This quote is not talking about pointers at all.

Seriously, don't try to learn C++ from the Dietels, they wrote a decent C book from what I hear (although if they really say that 'arrays are pointers', they didn't). but they definitely don't know C++ well enough to teach it.
Consider this reading list: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list
Last edited on
I didn't have any issues from that book still now! However do you know a good book then recommend it i will download that in epub/pdf
thanks all of you. . .i now have a better understanding :) Cheers!
Ahmad1797, you seem to have a number of misunderstandings on this subject.

An array is not a pointer. Section 4.2 of the standard[*] talks about Array-to-pointer conversion, if an array was a pointer you would not need this.

Section 8.3.4 basically says that a declaration T D where D has the form D[constant-expressionopt] is an array type (again not a pointer type).

When you use the name of an array it is converted to a pointer to the first element of the array.

sizeof() : When applied to a reference type, the result is the size of the referenced type
i.e. when applied to POINTER which is referenced DIRECTLY

Here, a pointer is NOT a reference type it is a pointer type.
You, like a lot of people, are getting confused with it being a reference and it referencing something.

======================================
[*] ISO/IEC 14882:2003 (the one I have to hand)
Topic archived. No new replies allowed.
Pages: 123