1. 程式人生 > >C語言陣列初始化

C語言陣列初始化

 /*C++使用new關鍵字分配記憶體,而C使用malloc(memory allocate)來分配記憶體*/
#include <stdio.h>
#include <malloc.h> 
/*使用typedef把int型別命名為新型別xx*/
typedef int ElemType;
typedef int Status;
/*結構體定義*/
typedef struct{
    ElemType *elem;
    int length;
}SqList;

Status InitList_Sq(SqList L){
    L.elem=(int *)malloc(sizeof(100));
if(!L.elem) exit(404);
L.length=0;
printf("%d",L.length);
return 0;
}

int main(){
/*型別變數*/
    SqList Sq;
    InitList_Sq(Sq);
    return 0;
}