% is part of conversion specifications such as %d or %f . Therefore, if you simply write %! , it will be interpreted as requiring a second argument matching the data type associated to ! (a so-called conversion specifier). printf("Hello, World%!"); will print Hello, World! . Furthermore, it will display a formatting warning at compilation.
Because the percent char is used internally, by the printf() function, as a part of a format specifier.
In essence, you're telling printf() to print out a value or variable, with the %! format protocol.
Which fails, because there is no %! format protocol, so printf() just prints out the exclamation point normally. It "eats" the % since it thought it was a format specifier, and it always "eats" format specifiers (replacing them with actual data in a specific format).
If you study your header files (stdio.h in this case), you might learn a lot, but the truth is, when you get far enough "under the hood" on these "Why?" questions, you'll wind up with one answer, before long:
"Because it was made that way".
C was made up by just a handful of programmers, based somewhat on the B language, which was based somewhat on the A language.
If you're going to have format specifiers for your print function, you have to have chars dedicated to those purposes. And you don't want those char's being printed, themselves.
i know that but i want to know the reason behind it why its happening
It is happening because in The C Programming Language by Brian W. Kernighan & Dennis M. Ritchie (Prentice Hall 1978) on page 147 (based on 15th printing) where it is finishing its description of the control string for printf, it says:
"If the character after the % is not a conversion character, that character is printed; thus % may be printed by %%."
In general, do not use this book as a reference; instead use the second edition which was published during the finalization of the ANSI stanard (C89).
This handling was continued during the standardization in ANSI C89 and ISO C90 which are nearly equivalent. I do not have access to either of these documents.
In the ISO C99 standard in section 22.214.171.124The fprintf function paragraphs 4 through 8, it describes the conversion specifications. At the end of paragraph 8, it says "% The % character is written. No argument is converted. The complete conversion specification shall be %%."
I hope this helps.
Edited 6 Years Ago by pheininger: grammar and typos
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
I am writing a java program that needs to execute shell commands, so I wrote a function that would take the command to execute as a string (ie: "mkdir ~/Folder1") and execute that command with the shell. Here is the function:
Runtime run = Runtime.getRuntime();
Process pr = ...
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...