69,336
社区成员
发帖
与我相关
我的任务
分享
char str[] = "class[0]";
test_func(&str);
int test_func(char **str)
{
char *p = NULL;
char *q = NULL;
char *substr = NULL;
printf("%s(), line = %d, str = %s \n", __func__, __LINE__, &(*str));
for (p = str, q = str; *p != '\0'; p++)
if (*p != '[' && *p != ']')
*q++ = *p;
*q = *p;
}
char str [] = "class[0]";
test_func (& str);
如果一元&运算符的操作数属于类型T,则&T的结果类型是指向T的指针。
str的类型是数组char [],故& str的类型是指向数组的指针char (*) []。
PS:一元&运算符的操作数必须是左值,且它的结果不是左值。因此
&str合法而&&str不合法。#include <stdio.h>
int test_func(char **str) {
char *p = NULL;
char *q = NULL;
printf("%s(), line = %d, str = %s \n", "test_func", __LINE__, *str);//test_func(), line = 6, str = class[0]
for (p = *str, q = *str; *p != '\0'; p++)
if (*p != '[' && *p != ']')
*q++ = *p;
*q = *p;
return 0;
}
int main() {
char str[] = "class[0]";
char *pstr=&str[0];
test_func(&pstr);
printf("%s",str);//class0
return 0;
}