Help me out.

#include <stdio.h> int main() { char str[] = "%d %c"; char a[] = "CodeQuotient"; return 0; } 1.)printf(str, 0[a], 2[a + 3]) 2)printf(str, 2[a], 3[a + 2]); what will be the output of this question:
11 Replies
the magic guy
the magic guy13mo ago
Try running it?
chandu8893
chandu889313mo ago
i did it but its not running ,
Σ
Σ13mo ago
Put the two printf statements above return 0 and you'll see the output
chandu8893
chandu889313mo ago
dont i have to make any change in that statement or it will be same?
Σ
Σ13mo ago
No changes
split
split13mo ago
split
split13mo ago
Yeah I'm bored 😒
chandu8893
chandu889313mo ago
thanks
Eakam
Eakam13mo ago
I might be missing something big but wth is 2[a]. I have seen a[2] but what does 2[a] do?
split
split13mo ago
pointer arithmetic lol a is a pointer.. you can do arithmetic (i.e +, -) on pointers. X[2] is the same as *(X + 2), which roughly translates to, the memory address X + 2, then dereference the resulting memory address. Therefore 2[X] is the same as *(2+X), which is the same as 2 plus the memory address X, then dereference this resulting memory address.
Eakam
Eakam13mo ago
Ah, ofc I totally forgot that was a thing Thanks for the refresher