An array
gives me answer 3 6 1.....can you help me understand this answer?Code:int a[2][3][2] = {{{1,2},{9,8},{3,7}},{{2,2},{1,4},{5,4}}} is declared printf("%d, %d, %d",a[1] - a[0],a[1][0] - a[0][0],a[1][0][0] - a[0][0][0]);
An array
gives me answer 3 6 1.....can you help me understand this answer?Code:int a[2][3][2] = {{{1,2},{9,8},{3,7}},{{2,2},{1,4},{5,4}}} is declared printf("%d, %d, %d",a[1] - a[0],a[1][0] - a[0][0],a[1][0][0] - a[0][0][0]);
My English is very poor ,I hope you can understand!
You must to think about the memory address!
a[1] and a[1][0] are address,a[1]==a[1][0] ,but they are differetly;
an address - an address == integer//a[1]-a[0] a[1][0]-a[0][0] I can understand ,but i don't know how to express! I 'm sorry!
a[1][0][0]==2
a[0][0][0]==1
you can look for some material about the pointer!
Well thanks a lot for your response..
you are saying that a[1]==a[1][0]....can you please explain with example of memory address?
The last %d is for a value. The first two are pointers that hold multiple numbers, so what you're getting there are the number of integer addresses, between one and the other.
Code:#include <stdio.h> int main(void) { int a[2][3][2] = {{{1,2},{9,8},{3,7}},{{2,2},{1,4},{5,4}}}; int i; printf("%d, %d, %d",a[1] - a[0],a[1][0] - a[0][0],a[1][0][0] - a[0][0][0]); printf("\n\nAddresses from a[0] to a[1]", a[0], a[1]); for(i=1;a[0]+i<=a[1];i++) printf("\n %p", a[0]+i); printf("\n\nAddresses from a[0][0] to a[1][0]", a[0], a[1]); for(i=1;a[0][0]+i<=a[1][0];i++) printf("\n %p", a[0][0]+i); printf("\n\n\t\t\t press enter when ready"); (void) getchar(); return 0; }