C编程中Struct Tag名称有什么用? [英] What is the use of Struct Tag name in C programming?

查看:17
本文介绍了C编程中Struct Tag名称有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道struct tag_name在C编程中的实际用途.在不使用 tag_name 的情况下,我也得到了与使用 tag_name 一样的输出.我想知道这个过程背后的确切原因.

I want to know the actual use of struct tag_name in C programming. Without using the tag_name also i was getting output as with use of tag_name. I want the exact reason behind this process.

例如:

//With tag_name st1
struct st1 { int x; char c;}x={100,'a'},y={70,'e'};

//Without any tag_name
struct { int x; char c;}x={100,'a'},y={70,'e'};

printf("x.x= %d \t x.c= %c \n",x.x,x.c);   //Output: x.x=100    x.c=a
printf("y.x= %d \t y.c= %c \n",y.x,y.c);   //Output: y.x=70     y.c=e

推荐答案

第一种情况:

struct st1 { 
    int x; 
    char c;
} x = {100, 'a'}, y = {70, 'e'};

您声明了一个名为 struct st1 的类型,并且您还创建了两个该类型的对象,xy.所以你可以随时创建这种类型的对象,就像这样:

you declare a type with name struct st1, and you also create two objects, of this type, x and y. So you can create objects of this type whenever you want, like this :

struct st1 obj1;

但是在第二种情况下:

struct { 
    int x; 
    char c;
} x = {100, 'a'}, y = {70, 'e'};

你创建了一个 struct 和两个对象,xy,但是你不能访问这个struct 再次.这意味着您不能创建任何这种类型的新对象.

you create a struct and two objects, x and y, but you cannot access this struct again. This means that you cannot create any new objects of this type.

这篇关于C编程中Struct Tag名称有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆