C program to print %% special symbol in c

In this example we will see how to print the special symbols %% in c. These special symbols tells compiler to do task when used in conjunction with some letters.


Special symbols, keywords, input output functions

How this thing functions?

% is used in conjunction with the characters to denote type of data we want to format to standard output. For instance, when we want to print data like integer, float and character then %d, %f and %c are the format specifiers that tells compiler that format the output in respective format and print the value.

These symbols are called as special symbols and they hold specific meaning when used in conjunction with characters. %c is used in printf() function then compiler will evaluate that character value should be printed and then compiler starts looking for argument after format specifier (ā€œ%cā€ )enclosed in double quotes.

Example: printf(ā€œ%cā€,Str); here Str variable holds the character and compiler prints the value by accessing that variable address.

Step by step approach:

In printf() function ,inside double quotes add % symbol 4 times and then close printf() statement by semicolon at end.

When % special symbol is escape character of printf() function so that when compiler encounter it then it escape it and expects immediate character after it that will tell it what to do? For example, when %d is encountered by compiler then it will escape % symbol and see next character d and interpret it as d stands for decimal and %d means print integer value and then starts looking for argument after %d.

So here, When first % is escaped then it expects next % to be string but second % does not get interpreted as command rather just a string that should be printed on screen so we get second % symbol printed and thus again we add another two % symbols and same execution follows and then 3rd % symbol gets interpreted as escape character and 4th % symbol gets printed as string.



Leave a Reply

%d bloggers like this: