Question

Can an address be assigned to an array name or an array element? Can an address...

Can an address be assigned to an array name or an array element? Can an address be assigned to a pointer variable whose object is an array?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Yes, we can assign an address to an array element.

below is an example.

int *p;   //this is an pointer variable of int type

int arr[10];    //this is an array of 10 elements

&arr[0] is holding the address of first element.

if we do like below

p = arr;

now p is pointing to the first element of the array. hence p is a pointer variable which is holding the address of the array.

in the following program output, you can clearly see that the address of the &arr[0] and pointer p is same.

=================================================================

Program:

=================================================================

#include<stdio.h>

int main()

{

int *p;

int arr[10];

printf("Address of arr[0] is %p\n", &arr[0]);

p = arr;

printf("Address of p is %p\n", p);

return 0;

}

==================================================================

Sample Output:

==================================================================

Kindly Check and Verify Thanks..!!!

Add a comment
Know the answer?
Add Answer to:
Can an address be assigned to an array name or an array element? Can an address...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT