By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,796 Members | 1,176 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,796 IT Pros & Developers. It's quick & easy.

How to convert value of array elements to array address?

P: 1
I doing doing C btw...

i have been trying to convert array elements into their respective addresses but Im faced with many problems.

eg. int x[6] (array with 7 elements)

im trying to set the 3rd element value = address of 3rd element of array


trying to make x[2] = &x[2]

but compiler says its an invalid conversion...

can i get some help pls?
Oct 27 '07 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,197
eg. int x[6] (array with 7 elements)
First, this is an array of 6 elements, not 7.

trying to make x[2] = &x[2]

but compiler says its an invalid conversion...
Yes, there is a problem. x[2] is an int. Whereas, &x[2] is the address of an int. The compiler distinguishes between an integer and the address of an integer.

There will be no way to make this conversion unless you lie to the compiler by saying the address of an int is an int. That will require a typecast.

Is this a homework assignment? I hope so since the conversion here makes no rational sense other than as an excercise.
Oct 27 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.