c语言初识
发布时间:2022-11-19 01:52:25 264 相关标签: # c++
- 指针
int main()
{
int num = 10;
int* p = # //int*为整形指针变量类型,其中变量p存储的是num的地址,*p==num
printf("%d\n", &num);
printf("%d\n", p); //打印num地址的两种方法
printf("%d\n", *p);
printf("%d\n", sizeof(p)); //指针变量的大小,在w32平台是4byte,在x64平台是8
return 0;
}
- 结构体
struct Book
{
char name[20];
short price;
};
int main()
{
struct Book b1 = { "c语言程序设计", 55 };
b1.price = 45; //结构体中的变量是可以直接更改的
strcpy(b1.name,"c++"); //结构体中的数组是无法直接更改的,需要使用strcpy指令更改,strcpy在库函数
struct Book* pb = &b1;
printf("%s\n", (*pb).name);
printf("%d\n", b1.price); //结构体成员引用,通过变量名引用
printf("%s\n", pb->name); //通过指针引用
return 0;
}
文章来源: https://blog.51cto.com/u_15744458/5553086
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报