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 2 of 5.
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.
Nagesh said:
9 years ago
Can anyone tell me if 7 is not mentioned in the code. Then what will be the output?
Thanks in advance.
Thanks in advance.
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?
7th no of char should be printed.
But I want to more than one char in given string.
How it possible?
Krishna said:
10 years ago
If I write,
printf("%c,%c \n", "infocom"[5][3]);
It show error:
Subscripted value is neither array nor pointer.
Why this is some one can explain me?
printf("%c,%c \n", "infocom"[5][3]);
It show error:
Subscripted value is neither array nor pointer.
Why this is some one can explain me?
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.
Pankajraj said:
10 years ago
@Wikiok.
Nice ans/example.
Compiler will check condition and print given character.
Nice ans/example.
Compiler will check condition and print given character.
Mohammed masood said:
1 decade ago
@Mj Taseen.
If %d is used it prints ASCII value of that character.
If %d is used it prints ASCII value of that character.
Mohammed masood said:
1 decade ago
If 0["indiabix"] then I.
If 1["indiabix"] then n and similarly others.
If 1["indiabix"] then n and similarly others.
Bins Emmanuel said:
1 decade ago
We can write a[i] = i[a].
Here they given second case,
Element[address]; i.e. When we are initializing a variable, it is mapping with address.
Eg: a ="indiabix".
a is stored with the base address of "indiabix" in code section.
So here,
7["indiabix"] = "indiabix"[7].
i.e assume address of indiabix stored in code section is 1000.
Then 1000[7].
1000[7] = *(1000+7) = *(1007) = x;
Note: The basic datatype of string is char, & ending with null char.
Here they given second case,
Element[address]; i.e. When we are initializing a variable, it is mapping with address.
Eg: a ="indiabix".
a is stored with the base address of "indiabix" in code section.
So here,
7["indiabix"] = "indiabix"[7].
i.e assume address of indiabix stored in code section is 1000.
Then 1000[7].
1000[7] = *(1000+7) = *(1007) = x;
Note: The basic datatype of string is char, & ending with null char.
(1)
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers