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