C Programming - Input / Output - Discussion

11. 

What will be the output of the program ?

#include<stdio.h>

int main()
{
    int a=250;
    printf("%1d\n", a);
    return 0;
}

[A]. 1250
[B]. 2
[C]. 50
[D]. 250

Answer: Option D

Explanation:

int a=250; The variable a is declared as an integer type and initialized to value 250.

printf("%1d\n", a); It prints the value of variable a.

Hence the output of the program is 250.


Suri said: (Aug 8, 2011)  
It will print the value of a after the space of whatever integer is given after %.

Sanjoy said: (Jan 27, 2014)  
Why 1 is used before d?

Vasavi said: (Jun 6, 2014)  
Here 1 indicates space. Before printing result it takes one space and print the value.

Vaishu said: (Aug 9, 2014)  
If we give %0.1d means what is the output of this program?

MITHUN YADAV said: (Aug 30, 2014)  
%0.1d means it will print one digit after decimal.

Sivasangeetha said: (Jul 24, 2015)  
Why 1 is used before d?

Rahul Gite said: (Aug 4, 2015)  
a=3.15529.

printf("%6.2f\n",a);

This means?

Muni said: (Jul 3, 2016)  
@Rahul Gite.

3.15.

Six spaces before it and two values after the decimal. Am I correct?

DarkoGH said: (Dec 15, 2016)  
You are right @Vasavi.

1 in front of %d is to allow for space.

Example %2d will give you two horizontal tab or two spaces before printing the next integer.

Sweety said: (Jun 4, 2017)  
Then what does "++" indicates after "%1d++\n"?

Payal said: (Apr 1, 2019)  
Please explain in detail.

Vishwambar said: (Dec 31, 2021)  
Thanks for explaining it.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.