C Programming - Input / Output - Discussion
Discussion Forum : Input / Output - Yes / No Questions (Q.No. 3)
3.
Will the following program work?
#include<stdio.h>
int main()
{
int n=5;
printf("n=%*d\n", n, n);
return 0;
}
Answer: Option
Explanation:
It prints n= 5
Discussion:
22 comments Page 1 of 3.
Bambi said:
1 decade ago
What is the significance of '*' in this ?
Vivek said:
1 decade ago
How it works? Please explain.
Madhusudan said:
1 decade ago
'*' will provide 4 spaces in between 'n=' and 5.
Rozario selvanathan said:
1 decade ago
Anyone please make it clear...
Veena said:
1 decade ago
I thought here two n's are not required. Please any one can explain.
Lakshmidevi said:
1 decade ago
Using * means it skips one variable, so only one n value is taken and another n value is ignored.
Nandhu said:
1 decade ago
Please anybody can explain this.
Medha said:
1 decade ago
One n is ignored with 4 space because of '*'and another n value is taken.
NITESH KHATRI said:
1 decade ago
#include<stdio.h>
int main()
{
int n=5,l=9;
printf("n=%*d\n", n, l);
return 0;
}
What @Medha said is correct, '*' will ignore the first variable and will print the value of l
Try to run this program, all confusion will be cleared.
int main()
{
int n=5,l=9;
printf("n=%*d\n", n, l);
return 0;
}
What @Medha said is correct, '*' will ignore the first variable and will print the value of l
Try to run this program, all confusion will be cleared.
Sunitha said:
1 decade ago
Here in printf("n=%*d\n", n, n);
("%*d",n,n) tells the compiler to skip the first n value.
Thus second n value gets printed.
("%*d",n,n) tells the compiler to skip the first n value.
Thus second n value gets printed.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers