2024年大数据最全C语言高级教程-C语言数组(二)_c语言中高维数组的作用 ,2024年最新差点无缘Offer
使用寻址运算符
发布日期:2025-06-20 11:29:05
浏览次数:12
分类:精选文章
本文共 1688 字,大约阅读时间需要 5 分钟。
Visual Studio 2019的开发环境具有以下特点:
默认安装Live Share代码协作服务:支持团队协作开发,实时同步代码。
优化开发体验:新增欢迎窗口,提升代码搜索功能,整体性能更优。
Visual Studio IntelliCode AI助手:通过AI技术提供智能代码完成建议。
改进Python支持:增强对Python虚拟机和Conda环境的支持。
全面.NET Core 3.0支持:包括WinForms和WPF项目。
C语言数组的学习可以从以下几个方面进行:
数组的定义与使用:通过代码示例展示如何定义和使用数组。
数组名称引用:解释数组名称如何引用一组数值。
实例演示:通过具体程序实例,掌握一维数组的定义和使用方法。
C语言中的寻址运算符&用于获取变量的内存地址。&广泛应用于scanf函数中,用于存储输入数据到变量中。通过在变量名称前添加&,可以获取该变量的地址。
使用寻址运算符&
以下程序将输出多个变量的地址:
#include#include int main() { system("color 3E"); long a = 1L; long b = 2L; long c = 3L; double d = 4.0; double e = 5.0; double f = 6.0; printf("A variable of type long occupies %u bytes.\n", sizeof(long)); printf("Here are the addresses of some variables of type long:\n"); printf("The address of a is: %p The address of b is: %p\n", &a, &b); printf("The address of c is: %p\n", &c); printf("A variable of type double occupies %u bytes.\n", sizeof(double)); printf("Here are the addresses of some variables of type double:\n"); printf("The address of d is: %p The address of e is: %p\n", &d, &e); printf("The address of f is: %p\n", &f); system("pause"); return 0;}
输出变量地址的格式
%u用于显示sizeof生成的值(无符号整数),%p用于输出内存地址(十六进制表示)。
输出数组变量地址
以下程序将输出数组中所有变量的地址:
#include#include #include int main() { system("color 3E"); int arrays[10]; srand(time(NULL)); for (int i = 0; i < 10; i++) { arrays[i] = rand() % 20 + 1; } for (int i = 0; i < 10; i++) { printf("%d of the address -> %p\n", arrays[i], &arrays[i]); } printf("\n"); system("pause"); return 0;}
"&数组名"的含义
&arrays表示获取数组arrays的首地址,即数组第一个元素的地址。
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2026年06月09日 14时17分48秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!