You are not logged in. Please login at www.codechef.com to post your questions!

×

# Pointers and Array in C.

 0 Consider this code fragment : int main() { int a[4]={1,2,3,4} printf("%d %d %d",a,&a,*a); }  This code is giving unexpected result! The value of "*a" is 1, which seems to be correct. But how come compiler is giving similar values of "a" and "&a"?? And even if "a" and "&a" have similar values, then in that case, should't "*a" be the same as "a" and "&a" ?? Since "a" is pointing to itself. Please Explain. Thank You. asked 18 Mar '15, 17:45 7●6 accept rate: 0%

 0 Arrays are basically pointers. The name of the array is the first memory location from where the array begins. In printf("%d %d %d",a,&a,*a); a represents the address of the location from which the array starts. &a is the usual way of saying the address of a, which is again the start location of the array. This is why they are giving similar answer. The last one, *a is the value at pointer a, i.e. the value at the location from which the array starts, which is the first element of the array. answered 18 Mar '15, 19:35 893●2●11●35 accept rate: 10% Your answer seems good. But in this case &a means "address of a". a is itself an address. So it just implies "address of an address" which is quite absurd. Isn't it? (18 Mar '15, 20:06)
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×862
×62

question asked: 18 Mar '15, 17:45

question was seen: 1,220 times

last updated: 19 Mar '15, 01:01