鹏哥C语言红皮书(26-28)笔记回顾

结构体

        例1:

//创建一个学生
struct Stu
{
    char name[20];
    int age;
    double score;
};

//创建一个书的类型
struct Book
{
    char name[20]; //成员变量
    float price;    
    char id[30];
};


int main()
{
    struct Stu s ={"张三",20,85.5}; //结构体的创建和初始化
    printf("1:%s  %d %if\n",s.name,s.age,s.score); //结构体变量,成员变量
    
    struct Stu *Ps = &s;
    printf("2:%s  %d %if\n",(*ps).name, (*ps).age, (*ps).score); //结构体变量,成员变量

    printf("3:%s  %d %if\n",ps->name, ps->age, ps->score); //结构体指针->成员变量名

    return 0;
}


        2.作业讲解

               1.不是C语言内置的数据类型:

                        题目内容:struct Stu

                2.局部变量的作用域是:

                        main函数内部

                3.下面代码的输出的结果是 num1

                        

#include<stdio.h>
int num = 10;
int main()
{
    int num = 1;
    printf("num=%d\n",num)
    return 0;

}

5.下面代码的结果是:(随机值)

#include<stdio.h>
#include<string.h>

int main()
{
    char arr[] = {'b','i','t'};
    printf("%d\n",strlen(arr));
    return 0;
}

6.不是转义字符的符号:\'q'

7.C语言中这个数组创建是错误的:

       

 int n = 10;int arr[n] = {0}

// c99标准中引用了一个概念:变长数组
//支持数组创建的时候,用变量指定大小的,但是这个数组不能初始化
//vs2019 不支持c99中变长数组的

8.下面的程序结果是:7

        

#include<stdio.h>
#include<string.h>
int main()
{
    printf("%d\n",strlen("C:\test\121"));
    return 0;
}

9.求两个数的较大值

        写一个函数求两个数的较大值

int Max(int x,int y)
{
    if(x>y)
        return x;
    else
        return y;
}

int main()
{
    int a = 0;
    int b = 0;
    scanf("%d %d",&a,&d);

    int m = Max(a,b);
    ptintf("%d\n",m);

    return 0;
}

10.关于C语言关键字说法正确的是:关键字可以自己创建

define

#define 预处理指令

include

#include 预处理指令

11.关于指针说法正确的是

        指针是个变量,用来存放地址

12.static说法不正确的是:

        static修饰的变量不能改变

      正确的是:

        1.static可以修饰局部变量

        2.static可以修饰全局变量

        3.static可以修饰函数

13.下面的代码结果:       

        

int sum(int a)
{
    int c = 0;
    static int b = 3;
    c+=1;
    b+=2;
    return(a+b+c);
}
int main()
{

    int i;
    int a = 2;
    for (i=0;i<5;i++){
      printf("%d",sum(a));  
};
}

14.用在switch语言中的关键字不包含那个? continue

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值