zoukankan      html  css  js  c++  java
  • printf那点事

    1、打印内存地址

    #include<stdio.h>
    int main()
    {
    	int a;
    	printf("%p
    ",&a);   //%p打印地址,自己主动加前缀00
    	printf("0x%x
    ",&a); //%x以十六进制打印
    	return 0;
    }
    输出结果:

    0012FF44
    0x12ff44


    2、printf,sprintf,snprintf

    原型:

    int printf(const char *format, ...);
    int sprintf(char *str, const char *format, ...);
    int snprintf(char *str, size_t size, const char *format, ...);
    sprintf 将字符串格式化输入到目标串中。

    snprintf将字符串最多复制 size-1 个字符到目标串中。

    #include<stdio.h>
    int main()
    {
    	char a[20];
    	char *p = "Hello,iot_xiaohe";
    	sprintf(a,"%s",p);
    	printf("sprintf a is: %s
    ",a);
    	snprintf(a,10,"%s",p);
    	printf("snprintf a is: %s
    ",a);
    	return 0;
    }
    输出结果:

    sprintf a is: Hello,iot_xiaohe
    snprintf a is: Hello,iot



  • 相关阅读:
    Properties类
    缓冲流
    Mybatis
    分页查询
    QueryRunner和JDBC连接池
    JSP
    Session
    Cookie
    http协议和eclipes绑定tomcat
    servlet
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/6767807.html
Copyright © 2011-2022 走看看