%d

For everyone, just starting with C++ or programming at all. Ask newbie questions in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

%d

Postby Valiantangel » Sat Apr 14, 2012 9:02 am

hi
in C if someone says
Code: Select all
printf(%d,x)
is x int and double or just int? I know %d is decimal .Will this be the same for
Code: Select all
printf(%d,&x);
?

Thanks
Valiantangel
 
Posts: 1
Joined: Sat Apr 14, 2012 1:19 am

Re: %d

Postby exomo » Sat Apr 14, 2012 1:00 pm

It sould be
Code: Select all
printf("%d",x);

x has to be int. printf does not check the parameters so if you pass double all you get is nonsense. For double you use %lf

&x means "address of the variable x", t print a pointer/address you can use %p.

See here http://www.cplusplus.com/reference/clib ... io/printf/ for a list of format parameters
Who needs a signature anyway.
User avatar
exomo
 
Posts: 880
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden


Return to For Beginners

Who is online

Users browsing this forum: No registered users and 3 guests