• C

urgent --array

hi,

i have an array like this arr[10] which has values.

now, i want to assign a pointer to the array like this;

arrpointer=arr;

but i want it to start from 1 and not zero...tq
zizi21Asked:
Who is Participating?
 
Infinity08Commented:
>> arrpointer = arr + sizeof(arr[0]);

That's incorrect.

The right way is :

        arrpointer = arr + 1;

or :

        arrpointer = &arr[1];

or something similar.
0
 
SpacemosesCommented:
arrpointer = arr + sizeof(arr[0]);
0
 
ozoCommented:
arrpointer = arr+1;
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
SpacemosesCommented:
could you write?

arrpointer = &arr + sizeof(arr[0]);
0
 
Infinity08Commented:
>> could you write?
>> 
>> arrpointer = &arr + sizeof(arr[0]);

No. adding to a pointer already adds sizeof(type) where type is the type the pointer points to. Using sizeof yourself adds too much.
For example, if sizeof(arr[0]) is 4, then arrpointer would point to the 5th element, not the second element.
0
 
ozoCommented:
only if sizeof(arr[0]) == 0

perhaps you were thinking of
(arrtype *)(((int)arr) + sizeof(arr[0]))
(which is not portable if (arrtype *) does not fit in an int
or
(arrtype *)(((char *)arr) + sizeof(arr[0]))
which is not a good idea either.
0
 
ozoCommented:
arr[i] is just another way of saying *(arr + i)
so
arr + sizeof(arr[0])
is equivalent to
&arr[sizeof(arr[0])]
0
 
zizi21Author Commented:
thanks a million
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.