#include <stdio.h>
int main()
{
char *arr = "This is to test";
printf("\n%c %c ",*(arr++), *(arr++));
return 0;
}
This program outputs h T rather than outputting h h. Why is it so?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
arr++ is equivalent to arr += 1. You are actually incrementing arr. This is what is happening in your situation.
What you want to do is
Note: As others have pointed out multiple pre/postfix ++/– produce undefined behavior (order of evaluation) and should be avoided, although I understand in your situation you were not trying to modify the original array.