码迷,mamicode.com
首页 > 其他好文 > 详细

结构体

时间:2016-11-26 03:00:17      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:sizeof   字符串   stdio.h   lib   字符   return   pause   print   struct   

#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;

}

结构体

标签:sizeof   字符串   stdio.h   lib   字符   return   pause   print   struct   

原文地址:http://www.cnblogs.com/liaoxianfu/p/6103318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!