unsigned long long int a[4][10] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,37,38,39,40}; printf("%lu",a); //5120 this is given printf("%lu",a+2); //5280 since a is 80 bytes, and 2*80 = 160, and 5120 + 160 = 5280 printf("%lu",a[2]); //also 5280 printf("%lu",*(a+2)+9); //answer is 5352 I don't understand how the answer is 5352 @photonics

5 months agotook me a while but i figured it out

5 months agoessentially the issue at play is that you're doing pointer arithmetic (something we never learned), but you have an array which is a pointer of pointers (in a sense) and you've dereferenced the pointer once

5 months agoprintf("%lu",*(a+2)+9); //answer is 5352 so *(a+2) would yield address 5280, but as an unsigned long long is 8 bytes having already dereferenced your pointer you get 5280+8*9=5352

5 months agoadmittedly I probably would not get this question correct on an exam, but hey, i already made it through the exams that would ask :D

5 months agoand if I dereference that entire thing printf("*lu*, *(*a+2)+9); that would be *(5352) which is the content at memory location 5352. right?

5 months agoHuh, it was 30 on the exam.

5 months agodoing math is hard

5 months agookay well yeah I get the idea at least.

5 months agoi mean you get the idea

5 months agothe issue is that on an exam you have to do it exactly and not just the idea

5 months agobut that's not my problem *shrug*

5 months agoHave you done R-values and L-values before?

5 months agoyeah but i don't remember them

5 months agobut hey i never even learned pointer arithmetic sooo

5 months agookay xd. I'll keep that in mind.

5 months agoI actually didn't know that an array in C was an array of pointers.

5 months agoit's not, but you can treat it as such

5 months agoit's really a single pointer wherein data is assumed to be stored in row major order

5 months ago