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

[Note]一些小坑点

时间:2018-07-30 21:38:25      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:lld   code   put   小例子   cpp   inpu   64位   include   not   

scanf

一个有趣的现象:如果用%lld或%I64d写入int的话,会出现一些神奇的现象,大概是因为强制写入了64位从而访问到了非法内存。

小例子:

#include <cstdio>

int a[3];

int main() {
    a[0] = a[2] = 2;
    scanf("%lld", &a[1]);
    printf("%d %d %d", a[0], a[1], a[2]);   
}
/*
input : 1
output : 2 1 0
input : 1000000000000
output : 2 -727379968 232
*/

[Note]一些小坑点

标签:lld   code   put   小例子   cpp   inpu   64位   include   not   

原文地址:https://www.cnblogs.com/wyxwyx/p/9392529.html

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