What is the Difference between "printf" and "sprintf"?

Answers were Sorted based on User's Feedback



What is the Difference between "printf" and "sprintf"?..

Answer / nelson

The only difference between sprintf() and printf() is that
sprintf() writes data into a character array, while printf
() writes data to standard output device.

Is This Answer Correct ?    118 Yes 10 No

What is the Difference between "printf" and "sprintf"?..

Answer / guest

prinf will print the data on to the screen.
sprintf will print the data to a buffer.

basically sprintf is used for formatting the output.

printf("%s",google);
char *p;
sprintf(p,"%s",google);

Is This Answer Correct ?    91 Yes 18 No

What is the Difference between "printf" and "sprintf"?..

Answer / prits

printf : Print formatted data to stdout (function)
sprintf:writes its results to a string instead of stdout

#include <stdio.h>

int main ()
{
char buffer [50];
int n, a=5, b=3;
n=sprintf (buffer, "%d plus %d is %d", a, b, a+b);
printf ("[%s] is a %d char long string\n",buffer,n);
return 0;
}

Is This Answer Correct ?    31 Yes 18 No

What is the Difference between "printf" and "sprintf"?..

Answer / namitha

printf is used to write the data in its format.
sprintf is used to write formatted data to string.

Is This Answer Correct ?    21 Yes 8 No

What is the Difference between "printf" and "sprintf"?..

Answer / praveen

printf writes the data to console
sprintf writes the data to an array

Is This Answer Correct ?    5 Yes 5 No

What is the Difference between "printf" and "sprintf"?..

Answer / lavanya

printf funtion is to write the output to stdout.
sprintf function is to store romatted input output on a
string buffer

Is This Answer Correct ?    11 Yes 13 No

What is the Difference between "printf" and "sprintf"?..

Answer / ramanji

printf() is used to send the output to the output consoled
device i.e,monitor

and the sprintf() is send the output to the specified file
that will be given in the parameters

Is This Answer Correct ?    8 Yes 11 No

Post New Answer

More C++ General Interview Questions

When does a name clash occur?

1 Answers  


Explain how the virtual base class is different from the conventional base classes of the opps.

0 Answers  


What is an object in c++?

0 Answers  


In a function declaration what does extern means?

0 Answers   Flextronics,


What is c++ stringstream?

0 Answers  






Can a constructor throw a exception? How to handle the error when the constructor fails?

1 Answers  


What is the difference between *p++ and (*p)++ ?

0 Answers  


what is the basic concept of c++(object oriented programing)

4 Answers   Wipro,


How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Why is it difficult to store linked list in an array?how can you find the nodes with repetetive data in a linked list?

0 Answers  


What is a character in c++?

0 Answers  


Explain shallow copy?

0 Answers  


What is difference between rand () and srand ()?

0 Answers  


Categories