C | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C

Escape sequences begin with a backslash \: \n new line \t horizontal tab \\ backslash \b backspace \' single quote \" double quote Format specifiers begin with a percent sign % and are replaced by corresponding arguments after the format string. A format specifier can include several options along with a conversion character: Help to understand

14th Nov 2020, 5:57 AM
Y.Rashid
Y.Rashid - avatar
3 Answers
+ 4
The role of the % sign in fornat specifiers is similar to that of \ in escape sequences. You need to tell to the compiler that you are going to print a float. How can you do that? Whatever you write in printf is going to be printed. The solution is to use %. Every time you use % the compiler is going to look for the following characters to put them together getting a special meaning. ps: if you just need to print a %, do %% not \%
14th Nov 2020, 8:54 AM
Davide
Davide - avatar
+ 3
If you want to print: CIAO you do: printf("CIAO"); If you want to print: "CIAO" and try to do that: printf(""CIAO""); you will get an error because the two double quotes before CIAO open and close a string to print. The same is for those after CIAO. So CIAO have no quotes. How can you tell to the compiler that you just want to print double quotes? The solution is to use the backslash. Eerytime you use the backslash in a code, the compiler is going to look for the next character and put them together to create an escape sequence. Doing \" tells to the compiler that the double quote is not to be used to open or close a string, but just as a character part of the string. Here's the proper printf: printf("\"CIAO\"");
14th Nov 2020, 8:43 AM
Davide
Davide - avatar
+ 1
this is fromc i didn’t understand First Complete your c course
14th Nov 2020, 6:01 AM
Y.Rashid
Y.Rashid - avatar