?
Solved

urgent --array

Posted on 2009-02-10
8
Medium Priority
?
185 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:zizi21
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Expert Comment

by:Spacemoses
ID: 23607112
arrpointer = arr + sizeof(arr[0]);
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 1400 total points
ID: 23607131
>> arrpointer = arr + sizeof(arr[0]);

That's incorrect.

The right way is :

        arrpointer = arr + 1;

or :

        arrpointer = &arr[1];

or something similar.
0
 
LVL 85

Assisted Solution

by:ozo
ozo earned 600 total points
ID: 23607135
arrpointer = arr+1;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:Spacemoses
ID: 23607144
could you write?

arrpointer = &arr + sizeof(arr[0]);
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 23607154
>> 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
 
LVL 85

Expert Comment

by:ozo
ID: 23607175
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
 
LVL 85

Expert Comment

by:ozo
ID: 23607197
arr[i] is just another way of saying *(arr + i)
so
arr + sizeof(arr[0])
is equivalent to
&arr[sizeof(arr[0])]
0
 

Author Comment

by:zizi21
ID: 23607229
thanks a million
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question