本文主要是介绍C语言之结构体新写法(三十八),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.方式一
#include <stdio.h>struct Student {char *name;int ival;char *chval;
};struct Student stu[] = {{.name = "JIM",.ival = 5,.chval = "ARM",},{.name = "GReen",.ival = 6,.chval = "X86",},
};int main(){//Way:1printf("name = %s, ival = %d, chval = %s\n",stu[0].name,stu[0].ival,stu[0].chval);printf("name = %s, ival = %d, chval = %s\n",stu[1].name,stu[1].ival,stu[1].chval);//结构体元素个数int count = sizeof(stu) / sizeof(struct Student);printf("count = %ld\n", count);//Way:2int i;for(i = 0; i < (sizeof(stu) / sizeof(struct Student)); i++){printf("name = %s, ival = %d, chval = %s\n",stu[i].name,stu[i].ival,stu[i].chval);}
}
2.方式二
#include <stdio.h>static const struct {const char *mName;const char *mLibNameSuffix;const char *mRole;} kComponents[] = {// two choices for aac decoding.// configurable in media/libstagefright/data/media_codecs_google_audio.xml// default implementation{ "OMX.google.aac.decoder", "aacdec", "audio_decoder.aac" },// alternate implementation{ "OMX.google.xaac.decoder", "xaacdec", "audio_decoder.aac" },{ "OMX.google.aac.encoder", "aacenc", "audio_encoder.aac" },{ "OMX.google.amrnb.decoder", "amrdec", "audio_decoder.amrnb" },{ "OMX.google.amrnb.encoder", "amrnbenc", "audio_encoder.amrnb" },{ "OMX.google.amrwb.decoder", "amrdec", "audio_decoder.amrwb" },{ "OMX.google.amrwb.encoder", "amrwbenc", "audio_encoder.amrwb" },{ "OMX.google.h264.decoder", "avcdec", "video_decoder.avc" },{ "OMX.google.h264.encoder", "avcenc", "video_encoder.avc" },{ "OMX.google.hevc.decoder", "hevcdec", "video_decoder.hevc" },{ "OMX.google.g711.alaw.decoder", "g711dec", "audio_decoder.g711alaw" },{ "OMX.google.g711.mlaw.decoder", "g711dec", "audio_decoder.g711mlaw" },{ "OMX.google.mpeg2.decoder", "mpeg2dec", "video_decoder.mpeg2" },{ "OMX.google.h263.decoder", "mpeg4dec", "video_decoder.h263" },{ "OMX.google.h263.encoder", "mpeg4enc", "video_encoder.h263" },{ "OMX.google.mpeg4.decoder", "mpeg4dec", "video_decoder.mpeg4" },{ "OMX.google.mpeg4.encoder", "mpeg4enc", "video_encoder.mpeg4" },{ "OMX.google.mp3.decoder", "mp3dec", "audio_decoder.mp3" },{ "OMX.google.vorbis.decoder", "vorbisdec", "audio_decoder.vorbis" },{ "OMX.google.opus.decoder", "opusdec", "audio_decoder.opus" },{ "OMX.google.vp8.decoder", "vpxdec", "video_decoder.vp8" },{ "OMX.google.vp9.decoder", "vpxdec", "video_decoder.vp9" },{ "OMX.google.vp8.encoder", "vpxenc", "video_encoder.vp8" },{ "OMX.google.vp9.encoder", "vpxenc", "video_encoder.vp9" },{ "OMX.google.raw.decoder", "rawdec", "audio_decoder.raw" },{ "OMX.google.flac.decoder", "flacdec", "audio_decoder.flac" },{ "OMX.google.flac.encoder", "flacenc", "audio_encoder.flac" },{ "OMX.google.gsm.decoder", "gsmdec", "audio_decoder.gsm" },
};
int main(){static const size_t kNumComponents = sizeof(kComponents) / sizeof(kComponents[0]);for (size_t i = 0; i < kNumComponents; ++i) {printf("xxx---> com_name = %s, suffix_name = %s, role = %s\n",kComponents[i].mName,kComponents[i].mLibNameSuffix, kComponents[i].mRole);}return 0;
}
这篇关于C语言之结构体新写法(三十八)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!