#C++ Code Help

30 messages · Page 1 of 1 (latest)

vernal lance
#

I got array size by using begin & end
And i really have no idea how begin & end gives this result "6"

Can someone help explaining?

young zealotBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

vernal lance
#

cout << end(nums) - begin(nums) << "\n";
How's end and begin working together to get me the array size ?

strong hedge
#

end gives you a pointer one past the last element of the array

#

begin gives you a pointer to the first element of the array

#

the difference of two pointers is the number of array elements between them

vernal lance
#

So end is not pointing to the last number
Its pointing to an imaginary number that comes after the last number

glad scaffold
#

its one past it

vernal lance
#

Sorry i don't get it
What means past ut

#

It*

glad scaffold
#

one past the last element

#

sorry lol

vernal lance
#

Okay but it still 5
I mean When I count the numbers, its 5, or 4 when I start with zero

glad scaffold
#

it can give you different results when you run

#

i think

vernal lance
#

Still 6

#

i feel dumb idk 🥹

glad scaffold
#

wait yes, it's the array size

vernal lance
#

We count from zero right?

glad scaffold
#

on indexing

vernal lance
#

Yes

#

Okay

glad scaffold
#

but it contains 6 elements

vernal lance
#

Do we start counting from the second number?

glad scaffold
#

shouldnt have confused

vernal lance
#

i just don't understand it
What you mean guys

#

Can i Skip it cuz i really can't understand it
I watched yt videos and the Indian guys saying that end is pointing into an imaginary number

frosty salmon
#

it's pointing one past the last element

frosty salmon