A More Optimal Way Of Looping Through String
Normally we're looping through a string like this
#include <stdio.h>
int main() {
char *myString = "this is my string";
while (*myString != '\0') {
putchar(*myString++);
}
}
We can simplify the while
loop:
#include <stdio.h>
int main() {
char *myString = "this is my string";
while (*myString) {
putchar(*myString++);
}
}
Since the value of nul
character is 0
anyways. And while
will terminate at 0
#include <stdio.h>
int main() {
printf("%d\n", '\0');
}
0