结构体

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
//结构体

struct student{
int age;
int sex;
char name[50];

};
struct A
{
int a;
char b;
long long c;

};
struct B
{
int a;

long long c;

char b;

};

int main(){
struct student xiaoming=
{
15, 0, "xiaoming"
};//第一种定义类型
//第二种定义
struct student xiaoming = {0};
xiaoming.age = 17;

xiaoming.sex = 0;

strcpy(xiaoming.name, "xiaoming");//strcpy字符串的拷贝


scanf("%s", &xiaoming.name);

printf("%s", xiaoming.name);

struct A a;
printf("%d\n", sizeof(a));//数组定义对齐 结果是16
struct B b;
printf("%d\n", sizeof(b));//数组定义对齐 结果是24

system("pause");
return 0;

}

posted @ 2016-11-25 23:21  过不去的过去  阅读(91)  评论(0编辑  收藏  举报