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