Quote:
|
Originally Posted by MikeWasHere05
Why do we use printf? I started c at the beginning of 6 weeks (minus about a week of c++), but knew PHP before that. In PHP you use the print statement where you just go
Code:
<?php
print "The variables value is: $variable";
?>
whereas in c you have to write
Code:
printf("The variables value is: %d", variable);
Can you use print() in c? If so why doesn't FIRST?
|
There isn't much of a difference between how the two functions are coded. Print() has the varible listed in the string. Printf() has the varible outside of the string. They work about the same. One difference is the d in %d could also be %f for floats and other things like that. This lets you say the type of varible you think you are going to see. It could truncate a long float if you don't need to see all of it. Or other things like that. Printf() is more powerful, and is coded about the same. Printf() just adds one more step.