C - 结构的名称是什么

标签 c arrays struct

我是初学者,正在学习C语言。 我学过数组,知道数组的名字就是它的第一个元素的地址,而数组的地址对应着数组所圈定的整个结构。

现在我正在研究结构,我想了解在这种情况下什么与结构的名称完全对应。 这些指令的输出结果:

#include <stdio.h>

struct numbers
{
       int b;
       int c;
};

int main(void)
{
       struct numbers some_numbers = {1, 0};

       printf("%d\n", some_numbers);
}

如下:

Output: 1

虽然这些指令的输出结果是:

#include <stdio.h>

struct numbers
{
       char a;
       int b;
       int c;
};

int main(void)
{
       struct numbers some_numbers = {0, 0, 0};

       printf("%d\n", some_numbers);
}

是下面的

Output: 7356928

结构的名称和它的第一个元素之间是否有任何联系,就像数组一样?

结构的名称应该很重要,否则如果我们想按值传递结构,为什么我们要使用结构的名称作为函数的参数?

最佳答案

如果您将 int 以外的任何内容传递给 printf("%d"),您将调用未定义的行为

关于C - 结构的名称是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48928165/

相关文章:

c - 错误: Parameter name omitted in C for structs

c - 映射文件函数路径

c - 这个在 c 中将中缀转换为后缀的程序给出了运行时错误。为什么?

c - 为什么当数组索引为3时输出为 "threefour",当索引为7时输出为 “seveneightnine”?

c++ - 使用 ReadConsoleInput() 拖动控制台窗口

sql - 将 postgresql 数组解包成行

javascript - 按最常见的项目在 javascript 中排序数组

pointers - 在 Go 中修改结构中的结构 slice

arrays - 如何从任何结构类型派生结构列表-从interface {}到变长 slice [] interface {}

c# - 如何在 Windows 窗体设计器中保存用户控件的结构属性?