C Programming - Strings - Discussion

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

int main()
{
    static char s[25] = "The cocaine man";
    int i=0;
    char ch;
    ch = s[++i];
    printf("%c", ch);
    ch = s[i++];
    printf("%c", ch);
    ch = i++[s];
    printf("%c", ch);
    ch = ++i[s];
    printf("%c", ch);
    return 0;
}
hhe!
he c
The c
Hhec
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
34 comments Page 1 of 4.

Nikhil said:   1 decade ago
How does an exclamation mark come?

Sumit said:   1 decade ago
Because here we are incrementing the value of s[4]. Before its space that is having ascii value 48 after incrementing it ll become '!'.

Devnath said:   1 decade ago
Replace 48 by 32, because white space ascii value is 32, and 33 is for "!".

Wikiok said:   1 decade ago
++i[s] <-> ++(i[s]) <-> ++(s[i])

Pallavi said:   1 decade ago
Can anyone explain the difference between i++[s] and ++i[s] ?

Pankaj said:   1 decade ago
i++[s] is equivalent to s[i]; i=i+1;

++i[s] is equivalent to ++(s[i]);

Uday said:   1 decade ago
In frist printf statement how 'ch' is get the value 104?

Midhu said:   1 decade ago
++i[s] <-> ++(i[s]) <-> ++(s[i]);

is it possible?

KHUSHBOO said:   1 decade ago
I don't understand it can anyone explain it clearly.

Prathima said:   1 decade ago
Here in last hhe! bcoz....ch=++i[s];
becomes ch=++(spacecharacter);
ch=++32
ch=33
in printf prints d ascii character of 33.


Post your comments here:

Your comments will be displayed after verification.