计算机科学cs50-笔记2

计算机科学cs50 上课笔记
原始网站

第11课 [第五周 1]

#include <cstdio>

void test_file() {
    FILE *fp;
    fp = fopen("file1", "w"); 
    if (fp != NULL) {
        int x = 101;
        fprintf(fp, "%d\n", x);
        fprintf(fp, "%d\n", x + 100);
        fprintf(fp, "%d\n", &x);

        fclose(fp);
    } else {
        printf("create file error");
    }
}

提供了“r”、“w”、“a”、“+”、“b”、“t”六种模式选择符号:

  • r 以只读方式打开文件;该文件必须存在
  • w 以只写文件打开文件;若文件存在则先文件清空;若文件不存在则建立该文件
  • a 以附加的方式打开只写文件;若文件不存在,则会建立该文件;如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。(EOF符保留)
  • + 可读写
  • b 二进制文件
  • t 文本文件

共有如下组合方式:

r
w
a
r+
w+
a+

rb
wb
ab
rb+
wb+
ab+

第12课 [第五周 2]

  1. 链表
struct student {
    int id;
    char *name;
    char *house;
    student *next;
};

typedef struct {
    int id;
    char *name;
    char *house;
} student2;

typedef struct node {
    int n;
    struct node *next;
} node;
  1. 队列

第13课 [第七周 1]

  1. typedef
//
// Created by morningcat on 2021/2/14.
//

//#include <cstdint>
//#include <cstdio>

#include <stdio.h>
#include <stdint.h>
#include "test13.h"

void test_13() {
    int8_t a1 = 128; // -128~127
    uint8_t b1 = 256; // 0~255
    u_int8_t c1 = 256; // 0~255

    printf("int8_t=%d\n", a1);
    printf("uint8_t=%d\n", b1);

    int16_t a2 = 32767; // -32768 ~ 32767
    uint16_t b2 = 65535; // 0~65535
    printf("int16_t=%d\n", a2);
    printf("uint16_t=%d\n", b2);

    int32_t a3 = 2147483647; // -2147483648 ~ 2147483647
    uint32_t b3 = 4294967295; // 0~4294967295
    printf("int32_t=%ld\n", a3);
    printf("uint32_t=%ld\n", b3);

    int64_t a4 = 9223372036854775807; // -9223372036854775808 ~ 9223372036854775807
    uint64_t b4 = 9223372036854775808; // ???
    printf("int64_t=%lld\n", a4);
    printf("uint64_t=%lld\n", b4);
}

#define FORMAT "2^%2d = %22lld\n"

void test_13_2(int n) {
    if (n < 1) { return; }
    int d = 2;
    unsigned long long rs = 1;
    for (int i = 1; i < n; ++i) {
        rs = rs * d;
        printf(FORMAT, i, rs);
    }
    rs = (rs - 1) * 2 + 1;
    printf(FORMAT, n, rs);
}
  1. PNG 位图

  2. valgrind

一款较好的检测程序内存问题的工具

valgrind -v --leak-check=full a.out

  1. 位运算

<<

&

第14课 [第七周 2]

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值