So I was given this sample code as an exercise and am having trouble understanding how exactly it works. I ran it and using some print statements I know it takes a string from the standard input and makes smaller versions of the string so hello becomes ello, then llo, then lo, then o. What I'm confused about is how source and target can have 1 added to them since their data type is a character pointer. How exactly does this code work?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
char* target = malloc(100*sizeof(char));
char* source = argv[1];
char tmp;
while ((*source) != 0) {
tmp = *source;
*target = tmp;
target = target + 1;
source = source + 1;
}
return 0;
}