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 guy2y ago
Try running it?
chandu8893
chandu8893OP2y ago
i did it but its not running ,
Σ
Σ2y ago
Put the two printf statements above return 0 and you'll see the output
chandu8893
chandu8893OP2y ago
dont i have to make any change in that statement or it will be same?
Σ
Σ2y ago
No changes
split
split2y ago
split
split2y ago
Yeah I'm bored 😒
chandu8893
chandu8893OP2y ago
thanks
Eakam
Eakam2y ago
I might be missing something big but wth is 2[a]. I have seen a[2] but what does 2[a] do?
split
split2y 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
Eakam2y ago
Ah, ofc I totally forgot that was a thing Thanks for the refresher
Want results from more Discord servers?
Add your server