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.
Kiran S P said:
5 years ago
Can anyone explain this and also interchange " printf("n=%**d\n", n, l);" and explain how it works?
#include<stdio.h>
int main()
{
int n=5,l=9;
printf("n=%**d\n", l, n);
return 0;
}
#include<stdio.h>
int main()
{
int n=5,l=9;
printf("n=%**d\n", l, n);
return 0;
}
Nandish said:
6 years ago
Here the spaces are printed in the first n and for the second n, the value has assigned. !
Aniruddha said:
8 years ago
* is a suppression character(which is optional after %), It suppresses the conversion that skips the content.
Loper said:
8 years ago
* means 4 spaces.
Hero said:
8 years ago
Can anyone explain how many spaces were there in the answer?
DipikaMore said:
9 years ago
@Ullesh.
#include<stdio.h>
int main()
{
int n=5,l=900,k=0;
printf("n=%*d\n", n, k,l);
return 0;
}
In this program, * will be replaced by the value of n & then next variable here is k will print. For l to print no access specifier. So it will not print anything.
#include<stdio.h>
int main()
{
int n=5,l=900,k=0;
printf("n=%*d\n", n, k,l);
return 0;
}
In this program, * will be replaced by the value of n & then next variable here is k will print. For l to print no access specifier. So it will not print anything.
Crystal said:
1 decade ago
@All.
Try these:
int main()
{
int i=10,j=20,k=30,l=40;
printf("%*d",i);//prints garbage
printf("%*d",i,j,k,l);//prints 2nd integer
printf("%*d",k);//garbage
}
Try these:
int main()
{
int i=10,j=20,k=30,l=40;
printf("%*d",i);//prints garbage
printf("%*d",i,j,k,l);//prints 2nd integer
printf("%*d",k);//garbage
}
PG srinu said:
1 decade ago
I think exactly * will ignore first variable then k l printed.
Ullesh Chavadi said:
1 decade ago
#include<stdio.h>
int main()
{
int n=5,l=900,k=0;
printf("n=%*d\n", n, k,l);
return 0;
}
What about this?
int main()
{
int n=5,l=900,k=0;
printf("n=%*d\n", n, k,l);
return 0;
}
What about this?
Ronak said:
1 decade ago
#include<stdio.h>
int main()
{
int n=5,l=9;
printf("n=%*d\n", n, l);
return 0;
}
What vijeth 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 vijeth 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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers