The thing about printf.

Source: Internet
Author: User

1. Print memory address

#include <stdio.h>int main () {int a;printf ("%p\n", &a);   %p Print address, the active prefix 00printf ("0x%x\n", &a); %x prints return 0 in hexadecimal;}
Output Result:

0012ff44
0x12ff44


2, printf. sprintf,snprintf

Prototype:

int printf (const char *format, ...); int sprintf (char *str, const char *format, ...); int snprintf (char *str, size_t size, const char *format, ...);
The sprintf string is formatted into the target string.

snprintf copies the string to a maximum of size-1 characters to the target string.

#include <stdio.h>int main () {char A[20];char *p = "Hello,iot_xiaohe"; sprintf (A, "%s", p);p rintf ("sprintf A is:%s\n ", a); snprintf (a,10,"%s ", p);p rintf (" snprintf A is:%s\n ", a); return 0;}
Output Result:

sprintf a Is:hello,iot_xiaohe
snprintf a Is:hello,iot



The thing about printf.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.