当前位置:网站首页>C escape character

C escape character

2022-06-24 07:39:00 Charming

1. C Commonly used escape characters

1) \t : A tab stop , Realize the function of alignment

2) \n : A newline

3) \\ : One \

4) \" : One "

5) \' : One '

6) \r : A carriage return printf(" Zhang Wuji, Zhao minzhou \r Zhi Ruo Xiaozhao ");

  • explain 2. Application example
  • \t Use of tab stops
#include <stdio.h>

void main(){
	printf(" Beijing \t Shanghai \t Guangzhou \t Shenzhen ");
	//  Keep the console from exiting 	
	getchar();
}
Insert picture description here
  1. \n Line feed use :
#include <stdio.h>

void main(){

	printf(" Zhang three said :\n Hello !");
	getchar();

}
Insert picture description here
  1. \\ : first \ It's the escape character , the second \ It's output \#include <stdio.h> void main(){ printf("hello,\\world!"); getchar(); }
    Insert picture description here
    4. \r Said the enter printf(" Zhang Wuji, Zhao minzhou \r Zhi Ruo Xiaozhao ");#include <stdio.h> void main(){ printf(" Zhang Wuji, Zhao minzhou \r Zhi Ruo Xiaozhao "); getchar(); }
    Insert picture description here
    3. practice #include <stdio.h> void main(){ printf(" full name \t Age \t Native place \t address \njohn\t12\t hebei \t Beijing "); getchar(); }
    Insert picture description here
  2. analysis : First, the output Zhang Wuji, Zhao minzhou , Find a \r enter , Will put the front Four characters Zhang Wuji Zhao ) Cover up , because \r There are four characters after enter , So the result of overwriting the first four characters : Zhiruo xiaozhaomin Zhou .
  3. The cursor finds that enter is directly positioned at Zhang , Put... Directly Zhang Wuji Zhao Replace it with
  4. requirement : Please use an output statement , Achieve the effect of outputting the following graphics
    Insert picture description here
原网站

版权声明
本文为[Charming]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/06/20210630131852414o.html