#include<stdio.h>
int main(void)
{
char heart[]="I Love Tillie"; /* using array notation */
int i;
for (i=0;i<6;i++)
{
printf("%c",&heart[i]); /* %c expects the address of the character we want to print */
}
return 0;
}
If heart[i] and &heart[i] mean the same thing , which is the address of heart[i], why is my program giving me this-??????, as output? Could someone please help me out here?
heart[i]is same as&heart[i]?charis the same as the address of a char (char *)?! I've explained this in an answer to one of your other questions, didn't I?char m1[] = "Like";or something similar. Saying thatm1 == &m1[0]is accurate. Saying that*m1 == 'L'is equivalent to sayingm1[0] == 'L'and given the initialization I showed is accurate. Similarly,*(m1+1) == 'i'andm1[1] == 'i'are individually accurate, but the composite statement*(m1+1) == m1[1] == 'i'does not evaluate to true in C, though it makes sense speaking loosely.