ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
what is the diff between the printf and sprintf functions?? 
and what is the syntax for this two functions ??
 Question Submitted By :: Varun
I also faced this Question!!     Rank Answer Posted By  
 
  Re: what is the diff between the printf and sprintf functions?? and what is the syntax for this two functions ??
Answer
# 1
printf statement print the result with comment
sprintf statement print the string
  Syntax
         printf(" ");
         sprintf(object name[argument]);
 
Is This Answer Correct ?    2 Yes 1 No
Guest
 
  Re: what is the diff between the printf and sprintf functions?? and what is the syntax for this two functions ??
Answer
# 2
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 ?    1 Yes 1 No
Jack
 
 
 
  Re: what is the diff between the printf and sprintf functions?? and what is the syntax for this two functions ??
Answer
# 3
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 ?    0 Yes 0 No
Vignesh1988i
 
  Re: what is the diff between the printf and sprintf functions?? and what is the syntax for this two functions ??
Answer
# 4
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 0 No
Santhi Perumal
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
what is the function of .h in #include<stdio.h> in c ? IBM9
int *a[5] refers to TCS8
write a code for large nos multilication (upto 200 digits) Persistent1
without using arithmatic operator convert an intger variable x into x+1  1
what will be the result of the following program ? char *gxxx() { static char xxx[1024]; return xxx; } main() { char *g="string"; strcpy(gxxx(),g); g = gxxx(); strcpy(g,"oldstring"); printf("The string is : %s",gxxx()); } a) The string is : string b) The string is :Oldstring c) Run time error/Core dump d) Syntax error during compilation e) None of these IBM2
suppose we use switch statement and we intilize years name using enum statement like(jan,feb,mar,------dec) we take integer value as an input .question is that the month which we analyz is from 0 to 11 bt if i enter 12 than how he again starts from begning and print jan  1
main() { printf("\n %d %d %d",sizeof('3'),sizeof("3"),sizeof(3)); } wat is the o/p and how?  7
a memory of 20 bytes is allocated to a string declared as char *s then the following two statements are executed: s="Etrance" l=strlen(s); what is the value of l ? a.20 b.8 c.9 d.21 TCS4
main() { char *ptr = "Ramco Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr); } Find the Outputs? CitiGroup7
What are the average number of comparisons required to sort 3 elements?  2
What will be printed as the result of the operation below: #include<..> int x; int modifyvalue() { return(x+=10); } int changevalue(int x) { return(x+=1); } void main() { int x=10; x++; changevalue(x); x++; modifyvalue(); printf("First output:%d\n",x); x++; changevalue(x); printf("Second output:%d\n",x); modifyvalue(); printf("Third output:%d\n",x); }  2
9.how do you write a function that takes a variable number of arguments? What is the prototype of printf () function? 10.How do you access command-line arguments? 11.what does ‘#include<stdio.h>’ mean? 12.what is the difference between #include<> and #include”…”? 13.what are # pragma staments? 14.what is the most appropriate way to write a multi-statement macro?  1
program to find the ASCII value of a number  5
Toggle nth bit in a given integer - num Qualcomm2
What are .h files and what should I put in them?  3
void main() { int i=5; printf("%d",i+++++i); } ME12
what is memory leak?  3
What is encapsulation?  1
Reverse the part of the number which is present from position i to j. Print the new number. eg: num=789876 i=2 j=5 778986  1
c programming of binary addition of two binary numbers  1
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com