I want to compare the adjacent characters in a string in a while loop, but the following 2 if statements give me different results.
1st: (this doesn't work)
if (input_str[k] == input_str[++k]) {
count++;
}
e.g. when k=0 then it should be "if (input_str[0] == input_str[1])"
2nd: (this works)
if (input_str[k++] == input_str[k]) {
count++;
}
e.g. when k=0 then it should be "if (input_str[0] == input_str[1])"
I guess the safe way will be the following code, but I still want to know why the other two if statement produce different results.
if (input_str[k] == input_str[k + 1]) {
count++;
}
k++;