アットウィキロゴ

構造体

  • 構造体配列
    #include<string.h>
    #include<stdio.h>
    struct employee{
    	int number;
    	char name[80];
    	int salary;
    };
    
    void main(){
    	struct employee person[2];
    
    	person[0].number=0007;
    	strcpy(person[0].name,"輿水");
    	person[0].salary=10000000;
    
    	person[1].number=0002;
    	strcpy(person[1].name,"中山");
    	person[1].salary=1000000;
    	for(int i=0;i<2;i++) printf("%d\n%s\n%d\n",person[i].number,person[i].name,person[i].salary);
    }
    
  • 構造体ポインタ(アロー演算子)
    #include<string.h>
    #include<stdio.h>
    struct employee{
    	int number;
    	char name[80];
    	int salary;
    };
    
    void main(){
    	struct employee koshimizu;
    
    	koshimizu.number=0007;
    	strcpy(koshimizu.name,"輿水");
    	koshimizu.salary=10000000;
    
    	struct employee *p;
    
    	p=&koshimizu;
    
    	printf("%d\n%s\n%d\n",p->number,p->name,p->salary);
    }
    

タグ:

+ タグ編集
  • タグ:
最終更新:2008年04月15日 09:32