+ 5
Why we use printf and in which situations
for c++
5 odpowiedzi
+ 5
printf is a standard C function that writes the results to standard output which is the screen. It somehow similar to cout object in C++.
We use it, because sometimes we would like to write C code rather than C++
+ 5
Dear R Ry
Thank u so much to explain it in details.
So the options are:
Dumb and fast vs. Smart and slow
+ 5
very very thanks
+ 3
we no more need printf in c++ , but yeah we need sprintf , and cprintf In c++ . We use cout instead of printf .
Sometimes printf works efficiently like in I the below case :-
printf("The value of the result is %c",&a);
Something like this .
+ 1
Just to add a bit to the other babak's answer, printf also tends to be much faster at outputting than std::cout because it is a simple function call while cout involves overloading operators from derived classes. printf can be easier to use than cout when you have to print something in more complex string formats. For example, to specify the width of what is printed, there is often less typing.
int i = 50;
printf("%*d", 5, i);
using namespace std;
cout << setw(5) << i;
But cout does type checking while printf doesn't. printf uses an ellipsis and treats additional arguments according to what was put in the format string (first argument). Above, printf expected an integer for the width and the integer to print.