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;
}
Discussion:
43 comments Page 3 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?
int main()
{
printf("%d\n", 7["IndiaBIX"]);
return 0;
}
If we write %d then output is 120 can any one explain me?
Manali said:
1 decade ago
char a[]="indiaBIX"
printf("%c \n",7[a]);
You will get same output.
printf("%c \n",7[a]);
You will get same output.
Shabana said:
1 decade ago
Here in the program.
I - 0.
n - 1.
d - 2.
i - 3.
a - 4.
B - 5.
I - 6.
X - 7.
The compiler will skip all 6 character and it will 7th character X only because of 7["IndiaBIX"].
I - 0.
n - 1.
d - 2.
i - 3.
a - 4.
B - 5.
I - 6.
X - 7.
The compiler will skip all 6 character and it will 7th character X only because of 7["IndiaBIX"].
Prasad said:
1 decade ago
Suppose take an example...
int a[3]={10,20,30};
printf("\n%d%d%d",0[a],1[a],2[a]);
same way as a[0] a[2]....
in the above example 7 is treated as index.
So it takes 7th character
int a[3]={10,20,30};
printf("\n%d%d%d",0[a],1[a],2[a]);
same way as a[0] a[2]....
in the above example 7 is treated as index.
So it takes 7th character
HARSHA said:
1 decade ago
It will print all characters after x in the string since there is only one character left it prints x
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
Devanshmody said:
1 decade ago
They have used %c so it will take one character and 7 is given and x is at 7 position.
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".
7["givenstring"] means it take 7th char of that string.
And string starts from 0 index.
Here "r".
Sindhu said:
1 decade ago
Thanks wikiok.
Lavanya said:
1 decade ago
Thanks venky, raghu and shamini.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers