|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||||
|
|||||
|
Why printf?
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"; ?> Code:
printf("The variables value is: %d", variable);
Can you use print() in c? If so why doesn't FIRST? |
|
#2
|
|||||
|
|||||
|
Re: Why printf?
Quote:
Don't forget, not all computers have the same outputs, so you can 'print' to several different things (a printer, a serial connection, a monitor). |
|
#3
|
||||
|
||||
|
Re: Why printf?
PHP is an interpreted language, but C is compiled. In C, everything in between the quotes is stored verbatim in the binary image that gets executed. By the time the program is compiled, your program no longer knows what the variable names were so it could not parse the variables out of the string. Even if it did know the variable names, it would need special knowledge of where the variable was actually stored.
I can't think of any way that it would even be possible to do this in C without doing some pre-processing before it got to the compiler. |
|
#4
|
||||
|
||||
|
Re: Why printf?
printf is print formatted
I know that in perl there is both print and printf but printf is far more powerfull |
|
#5
|
||||
|
||||
|
Re: Why printf?
Quote:
|
|
#6
|
|||||
|
|||||
|
Re: Why printf?
Thanks guys, I just wasn't too sure.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Printf Oddity : Programming Challange | DarkAlex | Programming | 7 | 21-03-2005 08:12 |
| printf statements do not display in autonomous mode | PVC Pirates | Programming | 3 | 22-02-2005 15:41 |
| Default Code and printf | WilsonDJ00 | Programming | 2 | 22-01-2005 16:39 |
| Anyone with a replacement Printf? | Larry Barello | Programming | 5 | 19-03-2004 02:20 |
| Printf warning during compile? | actorindp | Programming | 4 | 20-02-2004 17:02 |