C Programming - Input / Output - Discussion
Discussion Forum : Input / Output - Yes / No Questions (Q.No. 4)
4.
Can we specify a variable filed width in a scanf() format string?
Answer: Option
Explanation:
In scanf() a * in a format string after a % sign is used for the suppression of assignment. That is, the current input field is scanned but not stored.
Discussion:
6 comments Page 1 of 1.
Nishant said:
1 decade ago
Can anybody please explain me the answer.
Pruthvi said:
1 decade ago
Answer is YES. We can specify variable field width.
scanf("%2d",&a);
// will only take digits chars at run time.
scanf("%2d",&a);
// will only take digits chars at run time.
Mini said:
1 decade ago
@Pruthvi.
Thank you so much.
Thank you so much.
Dev said:
1 decade ago
What is the correct answer?
Sawant said:
1 decade ago
In scanf(), we can't use variable width specifier, we can only use like:
scanf("%4d",&a);
If you enter 12345678, the scanf simply scan the first 4 digits (ie) 1234 only.
But we can use variable width specifiers in printf():
printf("%*d",4,a);
4 is the width of the integer a.
scanf("%4d",&a);
If you enter 12345678, the scanf simply scan the first 4 digits (ie) 1234 only.
But we can use variable width specifiers in printf():
printf("%*d",4,a);
4 is the width of the integer a.
Nazima Khan said:
7 years ago
@All.
Thank you so much.
Thank you so much.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers