If we want to increment the null character '\0' by 60, given the string size is known beforehand, then we can do the following:
#include <stdio.h>
int main() {
char str1[] = "Hello!";
str1[6] += 60;
printf("%s\n", str1);
return 0;
}
The output we get is:
Hello!<
However, if we do not know the string size, then we can use strlen as such:
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "Hello!";
str1[strlen(str1) + 1] += 60;
printf("%s\n", str1);
return 0;
}
However, this outputs:
Hello!
As you can see, it doesn't change it at all. What am I doing wrong in the second case? Also, I thought that array size is static and does not change in size, so how can it be in the second case that we've "added" a character.