what is the difference between %d and %*d in c languaga?




Answers were Sorted based on User's Feedback



what is the difference between %d and %*d in c languaga?..

Answer / sivakumar

anand and manini your expectations are wrong. because %d
give the original value of the variable and %*d give the
address of the variable.
eg:-
int a=10,b=20;
printf("%d%d",a,b);
printf("%*d%*d",a,b);

result is 10 20 1775 1775
here 1775 is the starting address of the memory allocation
for the integer.a and b having same address because of
contagious memory allocation.

Is This Answer Correct ?    34 Yes 10 No

what is the difference between %d and %*d in c languaga?..

Answer / azad sable,chiplun.

In first case i.e. '%d' the '%' indicates that the
conversion specification follows. And 'd' known as data
type charactor indicates that the no. to be read is in
intiger mode.
* is an input field which specifie field width.
example
scanf("%d%*d%d",&a,&b);
will assign the data 123 456 789 as follows.123 to a 456
skipp because of * 789 to b.

Is This Answer Correct ?    6 Yes 3 No

what is the difference between %d and %*d in c languaga?..

Answer / satya

i will agree with sivakumar

Is This Answer Correct ?    3 Yes 1 No




what is the difference between %d and %*d in c languaga?..

Answer / vishal pandey

int v=23,d=89;
printf("%d %*d",v,d);
then o/p v=23 and d=address value and address value change with processor but original value does not change.

Is This Answer Correct ?    3 Yes 1 No

what is the difference between %d and %*d in c languaga?..

Answer / shivam chaurasia

The %*d in a printf allows you to use a variable to control the field width, along the lines of:
int wid = 4;
printf ("%*d
", wid, 42);

output,...
..42


if the form is like this...
printf ("%*d %*d
", a, b);
is undefined behaviour as per the standard, since you should be providing four arguments after the format string, not two (and good compilers like gcc will tell you about this if you bump up the warning level). From C11 7.20.6 Formatted input/output functions:

If there are insufficient arguments for the format, the behavior is undefined.

It should be something like:

printf ("%*d %*d
", 4, a, 4, b);


check this link for extra detail....
http://www.cplusplus.com/reference/cstdio/printf/

Is This Answer Correct ?    0 Yes 0 No

what is the difference between %d and %*d in c languaga?..

Answer / anand

both are same only and give the same out put

Is This Answer Correct ?    4 Yes 12 No

what is the difference between %d and %*d in c languaga?..

Answer / manini

according to me the ques has no meaning.

Is This Answer Correct ?    2 Yes 15 No

Post New Answer



More C Interview Questions

develop algorithms to add polynomials (i) in one variable

0 Answers   TCS, Ignou,


what is the output of the following program? main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }

7 Answers  


write a program to swap bits in a character and return the value prototype of function char fun (char a, charb flag c) where fun returns a char, char a is a the value char b is the bit to be changed and flag c is the bit value for eg: x=fun(45,7,0) since 45 is 0010 0101 and ow x should contain the value 65 (0110 0101)

1 Answers   Bosch, College School Exams Tests,


What is FIFO?

0 Answers  


Explain how to reverse singly link list.

0 Answers  






What will be your course of action for a push operation?

0 Answers  


Explain what is #line used for?

0 Answers  


What are pointers? Why are they used?

0 Answers  


What are the commands should be given before weiting C Program i.e, Cd.. like

4 Answers   IBM, Satyam, Infonet, Tech Mahindra,


An application package has been provided to you without any documents for the following application. The application needs to be tested. How will you proceed?

0 Answers   Infogain, Aspire,


Why static is used in c?

0 Answers  


Are the variables argc and argv are local to main?

0 Answers   TISL,






Categories