C-language printf () statement (top)

Source: Internet
Author: User

In the previous few posts, you'll find that I've used the printf () phrase many times, so today we'll talk about how to use the printf () statement.
First, let's look at the basic format of printf:

printf("输出的文字");printf("输出格式",需要输出的变量);

Let's start by demonstrating the first way to use:

#include<stdio.h>int main(void){        printf("Hello World");}

The program output is Hello World, this usage is very good understanding, no longer too much introduction. Let's focus on the second usage:

#include<stdio.h>int main(void){        int a;        a=1;        printf("%d",a);}

The program outputs a result of 1. Let's start with the output format, the output format is represented by a format character, and his laws are as follows:
Integral type data

format Characters Description
%d Signed integer in decimal number (positive not output symbol)
%o unsigned integers in octal (not output prefix 0)
%x,%x unsigned integers in hexadecimal numbers (not output prefix 0x)
%u Sign unsigned integers in decimal numbers

Real-data

format Characters Description
%f Output single, double-precision real numbers in decimal form
%e,%e Output single, double-precision real numbers in exponential form

Character type data

format Characters Description
%c Output a single character
%s Output string

In other words, what format do you want to output in "", and then write the variables that need to be output.

C-language printf () statement (top)

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.