#include<stdio.h>
#include<conio.h>
void main()
{
printf("%%%%%");
}
The output of the above program is %%% ,how come?
#include<stdio.h>
#include<conio.h>
void main()
{
printf("%%%%%");
}
The output of the above program is %%% ,how come?
This is simply, because the standard says:
4 Each conversion specification is introduced by the character %. After the %, the following appear in sequence:
[...]
8 The conversion specifiers and their meanings are:
[...]
% — A % character is written. No argument is converted. The complete conversion specification shall be %%.
(From ISO/IEC 9899:TC3 -> §7.19.6.1 Library)
You have unspecified behaviour. You have 5 %s in that format string. A % is followed by a format character, which controls what printf does with its arguments. So the 1st % is followed by another %, which printf outputs as a %. Similarly the 3rd and 4th %s.
However, the 5th % is followed by a null byte. And to quote the man page for printf:
If a character sequence in the format operand begins with a '%' character, but does not form a valid conversion specification, the behavior is unspecified.
So it could print %, print nothing, crash, ...
It depends on the compiler/platform... The fact you are using <conio.h>
tells me you are on DOS/Windows platform.
on the Linux side I get simply "%%" as output.
PS: please see What are the different valid prototypes of 'main' function?