sizeof strlen 指针 数组 解析sizeof, strlen, 指针以及数组作为函数参数的应用
人气:0想了解解析sizeof, strlen, 指针以及数组作为函数参数的应用的相关内容吗,在本文为您仔细讲解sizeof strlen 指针 数组的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:sizeof,strlen,指针,下面大家一起来学习吧。
代码如下所示:复制代码 代码如下:
typedef struct st_test
{
int id;
char *pName;
char class[10];
}Student;
void fn(Student *pStud) {
pStud->id = 10;
pStud->pName = "Tom Simith";
strcpy(pStud->class, "Class 1");
printf("sizeof(pStud) = %d /n", sizeof(pStud)); // sizeof(pStud) = 4
printf("sizeof(pStud->id) = %d /n", sizeof(pStud->id)); // sizeof(pStud->id) = 4
printf("id:%d/n", pStud->id); // id:10
printf("sizeof(pStud->pName) = %d /n", sizeof(pStud->pName)); // sizeof(pStud->pName) = 4
printf("strlen(pStud->pName) = %d /n", strlen(pStud->pName)); // strlen(pStud->pName) = 10
printf("Name:%s/n", pStud->pName); // Name:Tom Simith
printf("sizeof(pStud->class) = %d /n", sizeof(pStud->class)); // sizeof(pStud->class) = 10
printf("strlen(pStud->class) = %d /n", strlen(pStud->class)); // strlen(pStud->class) = 7
printf("class:%s/n", pStud->class); // class:Class 1
}
void fnArray(char arr[]) {
printf("arr:%s/n", arr); // arr:Hello
printf("sizeof(arr) = %d /n", sizeof(arr)); // sizeof(arr) = 4 The length of pointer
printf("strlen(arr) = %d /n", strlen(arr)); // strlen(arr) = 5 The length of array
}
int main(int argc, char **argv)
{
Student stud;
fn(&stud);
fnArray("Hello");
return 0;
}
加载全部内容