声明意义

扫码查看
本文介绍了声明意义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

char a [10];

将从索引0开始声明大小为10的字符数组。

what是以下声明的含义?什么是

这样的
声明?

char a [0];


谢谢,

Krishna

Hi all,
char a[10];
will declare character array of size 10 starting with the index 0.
what is the meaning of the following declaration? what is the purpose
of such
declarations?
char a[0];

thanks,
Krishna

推荐答案





它们有时被用来提供一个名字对于可变大小的数组,

位于''a''的地址。

例如:


#include < stdlib.h>


struct message

{

int type;

int length ;

char数据[0];

};

typedef struct message message_t;


message_t * create_message(int type,int length)

{

message_t * temp;

temp = malloc(length + sizeof(message_t)) ;

if(temp!= NULL)

{

temp-> type = type;

temp - >长度=长度;

}

返回温度;

}


int main ()

{

message_t * abc;

abc = create_message(10);

返回EXIT_SUCCESS;

}



They are used sometimes to provide a name for a variable size array,
located at the adress of ''a''.
For example:

#include <stdlib.h>

struct message
{
int type;
int length;
char data[0];
};
typedef struct message message_t;

message_t *create_message(int type, int length)
{
message_t *temp;
temp = malloc(length + sizeof(message_t));
if (temp != NULL)
{
temp->type = type;
temp->length = length;
}
return temp;
}

int main()
{
message_t *abc;
abc = create_message(10);
return EXIT_SUCCESS;
}



这篇关于声明意义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 23:37
查看更多