C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 15)
15.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    printf("%c\n", 7["IndiaBIX"]);
    return 0;
}
Error: in printf
Nothing will print
print "X" of IndiaBIX
print "7"
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
43 comments Page 3 of 5.

Kishanth said:   7 years ago
Thank you all for explaining it.

Aju said:   7 years ago
@Bins Emmanuel.

Nice explanation, Thanks.

Raghu said:   1 decade ago
It is just trick of mathematics. a[3] = 3[a] --> they are commutative both are expanded by compiler as *(a+3) and *(3+a) respectively. Even you can assign a variable to 3[a] = "X" which is same as a[3]="X".

Shamini said:   2 decades ago

printf("%c\n", 7["IndiaBIX"]);


It is printing the 7th character of the string "IndiaBIX".

I-0,
n-1,
d-2,
i-3,
a-4,
B-5,
I-6,
X-7.

Sathya said:   2 decades ago
Thanks Shamini.

Gopi said:   1 decade ago
Good. Thank you.

Narendra said:   1 decade ago
I think when we write like that then compiler will skip first 6 letters &then print remaining.

UmU said:   1 decade ago
@narender no you are wrong.

@samini good thnx. :).

Manoj said:   1 decade ago
Hey program is good, because whenever complier can't define any data type or user define %c means char or you can modify this program or define %f,
%d then you will get satisfied answer.

Wikiok said:   1 decade ago
myarray[5] == 5[myarray]


Post your comments here:

Your comments will be displayed after verification.