C Programming - Input / Output - Discussion

Discussion Forum : Input / Output - Find Output of Program (Q.No. 10)
10.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    printf("%%%%\n");
    return 0;
}
%%%%%
%%
No output
Error
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
36 comments Page 2 of 4.

K Jagannadham said:   1 decade ago
We can print % in C.

But another way to print % we need %% in C.

But to print %% we need %%% or %%%% in C.

And next to print %%% we need %%%%% or %%%%%% in C.
And so on.....

Bhavesh jain said:   1 decade ago
printf("%\n")

It will give output % . and to print % in c we have to add \n or \t or \r ..so it will terminate the % which starts finding for the d,s,c,f char to print something. so if we give \t ,\n then it will stop finding and simply print %.

Narayan said:   1 decade ago
I don't get anyone answer. Can anyone please explain about :

1. printf("%%%\n") (what will be o/p).
2. printf("%%\n") (what will be o/p).
3. printf("%\n") (what will be o/p).

Give ans respectively with proper explanation.

Pavani said:   1 decade ago
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
printf("%\n");//only one % is used
getch();
}
o/p:
%
Q:why it happened?

Ranjitha said:   1 decade ago
@josna:

If we print %%% the result is % and not %%.

Dheeraj said:   1 decade ago
Why printf("%??%%%%%\n"); giving output of %??%%% ?

Sneha said:   1 decade ago
Yes I got it.

Baadal said:   1 decade ago
Each % read the next single character hence it is printing only two %.

Ganesh said:   1 decade ago
My suggestion is, In C, we need a memory reference variable after the % symbol. In the above code, it considers % as memory reference variable and it prints. Try with %%%%%. It will print %%%. Its because, %% %% %.Split it into pair and then try it.

Sumedh said:   1 decade ago
I think it uses the first % as formate string and remaining two are printed and used \n to move cursor to next line.


Post your comments here:

Your comments will be displayed after verification.