Basic use zero-based C -05-printf of course

What is the input and output

Enter: "Mirror mirror tell me who the most beautiful in the world"
Output: "Snow White"
C programming, we will tell the program to their needs by calling the input function; by calling the output function, the program run results are displayed.

Using the input and output functions in the C standard library

It should include the header file stdio.h

#include <stdio.h>

Formatted output

The basic use of printf:
The first parameter is the format string, a percent represents the type of format to be formatted. Each symbol corresponds to a percent control of a subsequent parameter.

  • % D decimal output
  • Hexadecimal output% x,% X
  • % F floating point output
  • ASCII character output% c
  • % S output string

Other formatted output control character

  • Unsigned number% u
  • Pointer address% p
#include <stdio.h>

int main(int argc, char* argv[])
{
 //1. %d 十进制
 printf("%d\r\n", 100);

 //2. %X 十六进制
 printf("%X\r\n", 100); // 十六进制的 64
 printf("%X, %x\r\n", 11, 11);

 //3. %f 输出浮点数(小数)
 printf("%f\r\n", 3.1415926);

 //4. %c 是ASCII码对应的形式输出
 printf("%d, %c\r\n", 65, 65);

 //5. %s 以字符串形式输出
 printf("Your name is: %s\r\n", "LiSi");

 //6. %u 无符号形式输出(没有负数)
 printf("%d, %u\r\n", 0xFFFFFFFF, 0xFFFFFFFF);

 //7. %p 以指针形式输出
 printf("%p\r\n", 100);
 return 0;
}

Guess you like

Origin www.cnblogs.com/shellmad/p/11646139.html
Recommended