Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



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

Answer / guest

printf statement print the result with comment
sprintf statement print the string
Syntax
printf(" ");
sprintf(object name[argument]);

Is This Answer Correct ?    7 Yes 1 No

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

Answer / vignesh1988i

the printf and sprintf functions are used to output to the
screen.....
in printf... just we can print the necessary things as
we wanted
SYNTX is:: printf("format specifiers..(%d or %c
etc)",list of agruments..(arg1,arg2... arg n);
hrewr this function directly output whatever you are giving
inside ....
but sprintf is called Stream printf... where it will store
whatever we output to the screen in an array (ie..stream)
and then output to the screen;;;

sprintf(array base address,"format specifications",variables);

Is This Answer Correct ?    3 Yes 1 No

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

Answer / jack

The printf subroutine converts, formats, and writes the
Value parameter values, under control of the Format
parameter, to the standard output stream.

The sprintf subroutine converts, formats, and stores the
Value parameter values, under control of the Format
parameter, into consecutive bytes, starting at the address
specified by the String parameter. The sprintf subroutine
places a null character (\0) at the end. You must ensure
that enough storage space is available to contain the
formatted string.

Is This Answer Correct ?    2 Yes 1 No

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

Answer / manoj

i agree with Vignesh, and one more thing i would like to
add is,

ex:
char b[100];
sprintf( b, "Formatted data: %d / %f", i, f );


In above program, in array b string "Formatted data: %d / %
f" with proper i and f value will be stored.
it will not be printed on the output screen.

Is This Answer Correct ?    1 Yes 1 No

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

Answer / 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

More C Interview Questions

a=5 a=a++/++a

14 Answers   Bhel,


Explain what does a function declared as pascal do differently?

0 Answers  


What is structure of c program?

0 Answers  


Is printf a keyword?

0 Answers  


What will the code below print when it is executed?   int x = 3, y = 4;         if (x = 4)                 y = 5;         else                 y = 2;         printf ("x=%d, y=%d ",x,y);

0 Answers  


Can an array be an Ivalue?

0 Answers   EXL,


What is dangling pointer in c?

0 Answers  


Write a C program to print 1 2 3 ... 100 without using loops?

15 Answers   Hindalco,


What does stand for?

0 Answers  


what is the most appropriate way to write a multi-statement macro?

1 Answers  


Write a C program to perform some of the operation which can be performed using Single linked list

1 Answers   Qualcomm,


What is the difference between far and near in c?

0 Answers  


Categories