zoukankan      html  css  js  c++  java
  • C语言格式化字符串 %n 参数效果

    代码片段1

    #include <stdio.h>
    int main()
    {
        unsigned int x = 100;
        unsigned int y = 1;
        int *p = &x;
        printf("x=%d
    ", x);
        //printf("lalalala%n
    ", p);
        printf("%.66u%n
    ", y, p);
        printf("x=%d
    ", x);
        return 0;
    }
    

    代码片段2

    #include <stdio.h>
    int main()
    {
        unsigned int x = 0;
        unsigned int y = 0;
        int *p = &y;
        printf("&x=%.8p, &y=%.8p
    ", &x, &y); // y地址比x地址大4,先定义的整型参数先入栈,地址更高
        // printf("%.8p %.8p", p, (unsigned int*)p + 1); //(int)p+4);
        printf("x=%d, y=%d
    ", x, y);
        printf("000%n000000%n
    ", p, (unsigned int*)p + 1);
        printf("x=%d, y=%d
    ", x, y);
        return 0;
    }
    


    这是64位Ubuntu系统,对32位系统,代码中(unsigned int)应该改成(unsigned long)。因为64位系统unsigned long长度为8字节。

  • 相关阅读:
    总结:多校1
    简易数论练习
    2017 多校1
    简易数论函数变换学习
    petrozavodsk1
    Permutacja
    图片上传阿里云oss 数据存入redis List
    tp5实现月统计数据
    es6 新特性
    es6 新特性总结
  • 原文地址:https://www.cnblogs.com/Higgerw/p/14290705.html
Copyright © 2011-2022 走看看