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 2 of 5.

Mj taseen said:   1 decade ago
#include<stdio.h>

int main()
{
printf("%d\n", 7["IndiaBIX"]);
return 0;
}

If we write %d then output is 120 can any one explain me?

Nagendra said:   1 decade ago
@Taseen: you're wrong.

Because 120 is the ASCII for lowercase x.
The ASCII for uppercase x is 88.
In your program it is uppercase so output should be 88 not 120.

Varun said:   1 decade ago
No it will not print all the characters after 6 characters. if we keep 7+"IndiaBIX" then we will get output as you told..@narendra

Venky said:   1 decade ago
Actually: num[i]<=>*(num+i)<=>*(i+num)<=>i[num]

So 7 is index and indiabix is string. Thus X of indiabix.

Krishna said:   10 years ago
Here 7["indiabix"].

7th no of char should be printed.

But I want to more than one char in given string.

How it possible?

Mesv said:   1 decade ago
No need to think more.
7["givenstring"] means it take 7th char of that string.
And string starts from 0 index.
Here "r".

Saurav said:   9 years ago
This follows the rule: arr[x] = *(arr + x) = *(x + arr) = x[arr] where, arr is an array and x is an integer value.

Sathiya said:   2 decades ago
How does it takes 7th character("X") from IndiaBIX?

7["IndiaBIX"] shall we define like this?

Prakhar said:   10 years ago
7[IndiaBIX] is same as IndiaBIX[7] and printf("%c", IndiaBIX[7]) will print character at 7th index of IndiaBIX.

Rajutaya@gmail.com said:   1 decade ago
Ya correct guys, if it is printf("%d",7[indiabiA]);
means it will print the integer values as A=65


Post your comments here:

Your comments will be displayed after verification.