+ 1

I don't know how does this code work? Please help me understand the behaviour of this code in C

I don't know how it works correctly...... Without error..... Please focus on my comment on that code too.... https://code.sololearn.com/cwJ91wT1iP2k/?ref=app

26th Nov 2020, 1:57 PM
Yogeshwaran P
Yogeshwaran P - avatar
7 ответов
+ 3
a is a 2 dimentional array, so it needs 2 coordinates to give a value. a[0][0] is the first value a[0] is the address of the first sub-array a[0] would hold a value if 'a' was a one dimentional array
26th Nov 2020, 2:16 PM
Angelo
Angelo - avatar
+ 3
a[0] means a + 0*7 so it is indeed an address. It doesn't store a value, becouse it is a 2d array
26th Nov 2020, 2:05 PM
Angelo
Angelo - avatar
+ 3
Based on the comments in your code, you seem to have the misunderstanding that a[ 0 ] = *( a + 1 ) which is wrong, the index itself is the amount of offset to 'a', you don't add one to it, thus a[ 0 ] = *( a + 0 ) a[ 1 ] = *( a + 1 ) ... If an array decays to a pointer, it points to the first element of the array. Therefore, a[ 0 ] is a viable address here.
26th Nov 2020, 2:05 PM
Shadow
Shadow - avatar
+ 1
To add to the other answers this is the part if the course that explains pointer arithmetic for arrays https://www.sololearn.com/learn/C/2962/
26th Nov 2020, 2:09 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
0
Shadow sorry it's my mistake,while creating comments in code....😅 Now,I rectify that... but how does array decays to pointer...? in which condition it will happen like this? please help me to understand....
26th Nov 2020, 2:14 PM
Yogeshwaran P
Yogeshwaran P - avatar
0
😃 thanks a lot Angelo Landi now I understood that..... but,can you tell,how did you know that a[0] is considered as a address of first sub array.. where did you learn these at all? please tell me
26th Nov 2020, 2:21 PM
Yogeshwaran P
Yogeshwaran P - avatar
0
Angelo,Shadow Benjamin Jürgens please also see this thread... Help me to understand the doubt https://www.sololearn.com/Discuss/2603934/?ref=app
26th Nov 2020, 2:49 PM
Yogeshwaran P
Yogeshwaran P - avatar