c语言数组可以存储不同类型数据


#include "StdAfx.h" #include <stdio.h> #include <stdlib.h> typedef union { int intType; char charType; float floatType; const char* stringType; } AnyType; int main() { AnyType anyType[4]; anyType[0].intType    = 1; anyType[1].charType   = '2'; anyType[2].floatType  = 3.4f; anyType[3].stringType = "567"; printf("%d\n", anyType[0].intType); printf("%c\n", anyType[1].charType); printf("%f\n", anyType[2].floatType); printf("%s\n", anyType[3].stringType); system("pause"); return 0; }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM