I have a code which print pointer to const char
, or I mean a string
, recursively.
My code works fine when I'm using +=
operator to call print()
function. But, when I'm using ++
operator my code goes to an infinite loop just printing 'H'
.
Here's my code: TRY IT
#include <stdio.h>
void print(const char *s){
if(*s == 0)
return;
putc(*s, stdout);
print(s += 1); // infinite loop when `s++`
}
int main(void){
print("Hello");
return 0;
}
I know that in any loop for an example:
for(size_t i = 0; i < 10; i++) { }
is completely equivalent to
for(size_t i = 0; i < 10; i += 1) { }
Then, please tell what I'm missing out?