Field Width Specification

What is Field Width Specification?

Questions by sivarama vinaykumar   answers by sivarama vinaykumar

Showing Answers 1 - 3 of 3 Answers

picc_kumar

  • Sep 6th, 2008
 

field width specification means to allocate the a particular fixed  size of a varriable whether varriable is small in size or big.
eg:
if we allocate a field width of a varriable is 10 and the varriable is a[5] then it will just take a five block in to ten and another five block will be free.
by:- kamal kumar

  Was this answer useful?  Yes

kbjarnason

  • Jul 1st, 2010
 

Presumably the question is about the width specifier on bit-fields:

int x : 7;

In this case, the width specifier (7 in our example) tells the compiler that the bit-field (x) will use 7 bits, rather than the default number for the type.

The effect is to limit the range of allowable values to (in our example) the equivalent of what would be provided if the implementation used a 7-bit int type for x.

Note that other than limiting the range, the semantics of the base type remain in effect.

  Was this answer useful?  Yes

jbode

  • Jul 6th, 2010
 

I'm assuming this is the minimum field width in a conversion specification for printf(), which specifies the minimum number of characters written to the output stream for that conversion.  For example, given the statement

<pre>
printf("%10sn", "Hello");
</pre>

the 10 in "%10s" is the minimum field width; this means the value will be formatted so that at least 10 characters are written to stdout: "     Hello".  Note that this is a minimum width; if the value being written takes more than 10 characters to represent, then all the characters will be written, so the statement

<pre>
printf("%10sn", "Supercalifragilisticexpealidocious");
</pre>

results in the output "Supercalifragilisticexpealidocious". 

You can specify the field width at runtime by replacing the number with an asterisk and passing the value as an argument (int type):

<pre>
int width=10;
printf("%*sn", width, "Hello");
</pre>

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions