#include <stdio.h>
#include "../library/string.c"
int test(char* left, char* right) {
while ( *left != '\0') {
printf("%p\t%d, %d\n", left, (*left) + 1, *left);
left++;
}
return 0;
}
int main() {
char* a = "hello,kittz";
char* b = "hello,kitty";
test(a, b);
return 0;
}
when I execute the codes above , here are the output:
0x40073f 105, 104
0x400740 102, 101
0x400741 109, 108
0x400742 109, 108
0x400743 112, 111
0x400744 45, 44
0x400745 108, 107
0x400746 106, 105
0x400747 117, 116
0x400748 117, 116
0x400749 123, 122
But when i change the code to be :
int test(char* left, char* right) {
while ( *left != '\0') {
printf("%p\t%d, %d\n", left, (*left)++, *left);
left++;
}
return 0;
}
The output tell me that there is something wrong occurs. Here is the output: Segmentation Fault (core dumped).