The basic course of C language (iii) input and output functions and control flow statements (3)

Source: Internet
Author: User
Tags clear screen header integer printf
2. Some special specified characters
━━━━━━━━━━━━━━━━━━━━━━━━━━
Character function
──────────────────────────
\ n Line Change
\f Clear screen and change page
\ r Carriage Return
\ t Tab character
\XHH represents an ASCII code with a 16-in representation,
where HH is 1 to 2 16 in number
━━━━━━━━━━━━━━━━━━━━━━━━━━
The printf () function learned in this section, combined with the data type learned in the previous section, compiles the following program to deepen understanding of the turbo C2.0 data type.
Example 1
#include <stdio.h>
#include <string.h>
int main ()
{
Char c, s[20], *p;
int a=1234, *i;
float f=3.141592653589;
Double x=0.12345678987654321;
P= "How to Do";
strcpy (S, "Hello, comrade");
*i=12;
c= ' \x41 ';
printf ("a=%d\n", a); /* Result output decimal integer a=1234*/
printf ("a=%6d\n", a); /* Results output 6-bit decimal number a= 1234*/
printf ("a=%06d\n", a); /* Results output 6-bit decimal number a=001234*/
printf ("a=%2d\n", a); /*a more than 2 digits, output a=1234*/by actual value
printf ("*i=%4d\n", *i); /* Output 4-bit decimal integer *i= 12*/
printf ("*i=%-4d\n", *i); /* Output left-aligned 4-bit decimal integer *i=12*/
printf ("i=%p\n", I); /* Output Address i=06e4*/
printf ("f=%f\n", f); /* Output floating-point number f=3.141593*/
printf ("f=6.4f\n", f); /* Output 6-bit floating-point number 4 digits after the decimal point
f=3.1416*/
printf ("x=%lf\n", X); /* Output long floating-point number x=0.123457*/
printf ("x=%18.16lf\n", x);/* Output 18-bit long floating-point with 16 digits after the decimal point
Number x=0.1234567898765432*/
printf ("c=%c\n", c); /* Output character c=a*/
printf ("c=%x\n", c); /* The ASCII code value of the output character c=41*/
printf ("s[]=%s\n", s); /* Output array string S[]=hello, comrade*/
printf ("s[]=%6.9s\n", s);/* Output A string of up to 9 characters S[]=hello,
co*/
printf ("s=%p\n", s); /* Output array string first character address s=ffbe*/
printf ("*p=%s\n", p); /* Output pointer string p=how do your do*/
printf ("p=%p\n", p); /* The value of the output pointer p=0194*/
Getch ();
RETUNR 0;
}
The address values in the results above may be different on different computers.
Example 1. The meaning of the first statement #include<stdio.h> is to invoke another file stdio.h, which is a header file that includes the data type definitions and function descriptions for all standard input and output library functions. The variable and function types used by the Turbo C2.0 for each library function have been defined and described, placed in the corresponding header file "*.h", and the user must use these functions with #include<*.h> or #include "*. H "statement to invoke the corresponding header file for the connection. If this statement is not described, an error will occur when the connection is made.
Related Article

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.