C技能树:打印学生基本信息
用不同的基本数据类型保存一名学生的各项信息,并打印输出。请判断以下选项中哪一个能更好地存储学生的基本信息,选出正确答案填在(1)处。
#include <stdbool.h>
#include <stdio.h>
int main(int argc, char argv)
{(_____1_____)printf("学号:\\t%d\\n", student_id);printf("姓名:\\t%s\\n", name);printf("性别:\\t%s\\n", sex);printf("年龄:\\t%d\\n", age);printf("身高:\\t%.2f\\n", height);printf("体重:\\t%.2f\\n", weight);printf("是否独生子女:\\t%s\\n", only_child ? "是": "否");return 0;
}
int student_id = 1001;
char name[] = "张三";
char sex = '男';
int age = 18;
bool only_child = true;
float height = 170.50;
float weight = 55.25;
//错误
int student_id = 1001;
char name[] = "张三";
char sex[] = "男";
int age = 18;
bool only_child = true;
int height = 170.50;
int weight = 55.25;
//错误
char student_id = 1001;
char name[] = "张三";
char sex[] = "男";
int age = 18;
bool only_child = true;
float height = 170.50;
float weight = 55.25;
//错误
int student_id = 1001;
char name[] = "张三";
char sex[] = "男";
int age = 18;
bool only_child = true;
float height = 170.50;
float weight = 55.25;
//正确
解析:本题考查内容为变量的类型和占位符之间的关系,根据printf中的占位符我们能看出变量定义的字符依次为整型、字符串、字符串、整型、实型、实型布尔类型