I'll play. Let's add just a little more code.
#include <stdio.h>
#include <string.h>
char a[] = "STD C";
char b[] = "FUBAR";
char c[] = "HEHAW";
void bar(char *w)
{
w = b;
printf("in bar *w =%s\n", w);
printf("in bar sizeof w is %d, sizeof *w is %d, "
"sizeof b is %d, sizeof *b is %d\n",
(int)sizeof w, (int)sizeof *w,
(int)sizeof b, (int)sizeof *b);
}
void normal(char *w)
{
strcpy(w, c);
printf("in normal *w =%s\n", w);
printf("in normal sizeof w is %d, sizeof *w is %d, "
"sizeof b is %c, sizeof *c is %d\n",
(int)sizeof w, (int)sizeof *w,
(int)sizeof c, (int)sizeof *c);
}
void foo(void)
{
char *ptr;
ptr = a;
bar(ptr);
Replace the above line with
bar(a);
printf("in foo sizeof a is %d, sizeof *a is %d, "
"sizeof ptr is %c, sizeof *ptr is %d\n",
(int)sizeof a, (int)sizeof *a,
(int)sizeof ptr, (int)sizeof *ptr);
/* what is ptr pointing at? */
/* if C is pass by value it is a */
/* if C is pass by reference it is b */
printf("in foo *ptr =%s\n", ptr);
/* bar can't change *ptr, but it could change its object */
normal(ptr);
Replace the above line with
normal(a);
printf("in foo sizeof a is %d, sizeof *a is %d, "
"sizeof ptr is %c, sizeof *ptr is %d\n",
(int)sizeof a, (int)sizeof *a,
(int)sizeof ptr, (int)sizeof *ptr);
printf("in foo *ptr =%s\n", ptr);
/* end of lesson */
}
int main(void)
{
foo();
return 0;
}
Since the same value gets passed to normal and bar (namely &a[0]), my
code changes shouldn't alter the validity of your conclusions.