Following is my code:
#include <stdio.h>
int main()
{
char a[10]="Hi!";
void f(char b[])
{
// 1. printf("*a is:%s
",*a);
printf("&a is:%p
",&a);
// 2. printf("&&a is:%p
",&(&a));
printf("a's address is:%p
",a);
printf("a's value is:%s
",a);
printf("b's address is:%p
",b);
printf("b's value is:%s
",b);
// 3. printf("*b is:%s
",*b);
printf("&b is:%s
",&b);
}
f(a);
return 1;
getch();
}
Running the above code gives the output:
&a is:0028FF1C
a's address is:0028FF1C
a's value is:Hi!
b's address is:0028FF1C
b's value is:Hi!
&b is:∟?(
In the Output:
Why are there different outputs for &a
and &b
;
Although a and b have same reference.
Further,
I've mentioned 3 comments by their number.
If I remove slashes one by one and execute them,I get following 2 issues:
On executing comment no. 1 & 3:
"abc.exe has stopped working."
On executing comment no. 2:
abc.c: In function 'f':
abc.c:14:32: error: lvalue required as unary '&' operand
printf("&&a is:%p
",&(&a));
^
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…