I have just started learning C.
void function(char *str1, char *str2) {
printf("%p\n", str1);
printf("%p\n", str2);
str1++; //*str++;
str2++; //*str++;
printf("%p\n", str1);
printf("%p\n", str2);
}
int main(int argc, char *argv[]) {
function(argv[1], argv[2]);
return 0;
}
if argv[1] is “basic” argv[2] is “program”;
when I replace the code with comment part, it would give the same result, which is "a" "r";
but if I compile it with flag -Werror, it would give “warning : value computed is not used”
What is difference between str1++ and *str1++;?
what is the code if i want to increment the character it points to
for the line : function(argv[1], argv[2]); in here the argv[1] and agrv[2] I pass to the function, are they pointers or they are the array?
what is *argv[1] and *argv[2]
They have exactly the same side-effects (increment the pointer).
They heve, however, different values. The first evaluates to the value of the pointer before incrementing, the second evaluates to data it points to. You don’t use the value anyway, which is what your compiler is noticing you about.
They are pointers to char, ie. strings. Particularly the 1st and 2nd command line parameters.