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;
}
Discussion:
36 comments Page 1 of 4.
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 %.
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.
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.
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.
Kamlesh Lohar said:
8 years ago
First % is take as identifier and next take as value that's why output is %%.
Because 1st taken as identifier and 2nd as value and just like 3rd taken as identifier and 4th as value.
Because 1st taken as identifier and 2nd as value and just like 3rd taken as identifier and 4th as value.
(2)
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.....
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.....
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?
#include<conio.h>
main()
{
clrscr();
printf("%\n");//only one % is used
getch();
}
o/p:
%
Q:why it happened?
Kartik Raghav said:
8 years ago
@Niranjan: if we input %% then output ill be single %. If we input %%% then output will same single %.
What is logic behind it? explain?
What is logic behind it? explain?
(1)
Premnath said:
1 decade ago
Ya the answer given by Niranjan is correct and also the ans given by the Salesh is also correct.
Thanks to both of them.
Thanks to both of them.
Niranjan said:
2 decades ago
Because we can't print % in C.
To print % we need %% in C for printing single %.
Hence to print %% we need %%%%.
To print % we need %% in C for printing single %.
Hence to print %% we need %%%%.
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:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers