c语言 12-1

1、

#include <stdio.h>

#define NAME_LEN 64

struct student{   //结构体声明 
    char name[NAME_LEN];
    int height;
    float weight;
    long schols;
};

int main(void)
{
    struct student takao = {"Takao", 173, 87.3};  //结构体成员初始化 
    
    printf("takao.name = %s\n", takao.name);  //对象(结构体)takao各成员的值 
    printf("takao.height = %d\n", takao.height);
    printf("takao.weight = %.1f\n", takao.weight);
    printf("takao.schols = %ld\n", takao.schols);
    
    puts("\n======================");
    printf("address of takao.name: %p\n", &takao.name);  //结构体各成员的地址 
    printf("address of takao.height: %p\n", &takao.height);
    printf("address of takao.weight: %p\n", &takao.weight);
    printf("address of takao.schols: %p\n", &takao.schols);
    return 0;
}

 

posted @ 2021-06-03 21:29  小鲨鱼2018  阅读(35)  评论(0编辑  收藏  举报