what is the diff between the printf and sprintf functions??
and what is the syntax for this two functions ??

Answer Posted / santhi perumal

sprintf: This Writes formatted data to a character string in
memory instead of stdout

Syntax of sprintf is:

#include <stdio.h>
int sprintf (char *string, const char *format
[,item [,item]...]);

Here

String refers to the pointer to a buffer in memory where the
data is to be written. Format refers to pointer to a
character string defining the format. Each item is a
variable or expression specifying the data to write.

The value returned by sprintf is greater than or equal to
zero if the operation is successful or in other words the
number of characters written, not counting the terminating
null character is returned. And return a value less than
zero if an error occurred.

printf: Prints to stdout

Syntax for printf is:

printf format [argument]...

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

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the 4 types of functions?

665


Can 'this' pointer by used in the constructor?

701


When was c language developed?

799


What are the advantages of union?

718


what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above

771






What is a scope resolution operator in c?

844


Write a code to generate a series where the next element is the sum of last k terms.

841


Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result

1554


What is meant by recursion?

713


How many bytes are occupied by near, far and huge pointers (dos)?

792


What is the difference between union and structure in c?

675


Which type of language is c?

740


What is else if ladder?

699


Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?

701


In C, What is the #line used for?

1267