Here is a good example on why either you love C++ or hate it with such terse expression oriented code; I think its pretty cool.

If you want to copy one string to another, one option can be something like this.

1
2
3
4
5
6
void mycopy(char *p, char *q) {
    int len = strlen(q);
 
    for(int i=0; i<=len; i++)
        p[i] = q[i];
}

However this achieves the same thing as above and is more efficient:

1
2
3
void mycopy(char *p, char *q) {
    while(*p++ = *q++);
}

Of course why would you write your own version when you have standard string copy fundtion strcpy in <string.h>