学会思考
刻意练习
#include <iostream>
using namespace  std;

int main() {
    cout << "Hello, World!" << endl;
    char buf[2];
    sprintf(buf,"%d",12);
    cout << buf <<endl;
    return 0;
}

崩溃,

原因:

char buf[2];//大小为2

sprintf(buf,"%d",12);//12转化为"12"(以"\0"结尾),大小为3,数组下标越界;

posted on 2020-11-20 11:01  Worty  阅读(122)  评论(0编辑  收藏  举报