相关疑难解决方法(0)

801
推荐指数
5
解决办法
49万
查看次数

typedef struct vs struct definitions

我是C编程的初学者,但我想知道typedef在定义结构时使用与使用结构之间有什么区别typedef.在我看来,实际上没有区别,他们实现了同样的目标.

struct myStruct{
    int one;
    int two;
};
Run Code Online (Sandbox Code Playgroud)

typedef struct{
    int one;
    int two;
}myStruct;
Run Code Online (Sandbox Code Playgroud)

c struct typedef

763
推荐指数
10
解决办法
66万
查看次数

在C++中的变量声明中使用struct关键字

我觉得这可能与C语法有关,但我用C++开始编程,所以我不确定.

基本上我已经看到了这个:

struct tm t;
memset( &t, 0, sizeof(struct tm) );
Run Code Online (Sandbox Code Playgroud)

我对这种语法有点困惑,因为通常我希望上面的内容看起来像这样:

tm t;
memset( &t, 0, sizeof(tm) );
Run Code Online (Sandbox Code Playgroud)

这两者之间有什么区别,为什么要使用前者呢?

更新

tm我所指的结构是wchar.h,其定义如下:

struct tm {
        int tm_sec;     /* seconds after the minute - [0,59] */
        int tm_min;     /* minutes after the hour - [0,59] */
        int tm_hour;    /* hours since midnight - [0,23] */
        int tm_mday;    /* day of the month - [1,31] */
        int tm_mon;     /* months since January - [0,11] */
        int tm_year;    /* years …
Run Code Online (Sandbox Code Playgroud)

c++ struct

25
推荐指数
2
解决办法
2万
查看次数

标签 统计

struct ×3

c++ ×2

typedef ×2

c ×1