sprintf() in C Last Updated : 10 Jan, 2025 Comments Improve Suggest changes 54 Likes Like Report Syntax: int sprintf(char *str, const char *string,...); Return: If successful,it returns the total number of characters written excluding null-character appended in the string, in case of failure a negative number is returned .sprintf stands for “String print”. Instead of printing on console, it store output on char buffer which are specified in sprintf. C // Example program to demonstrate sprintf() #include <stdio.h> int main() { char buffer[50]; int a = 10, b = 20, c; c = a + b; sprintf(buffer, "Sum of %d and %d is %d", a, b, c); // The string "sum of 10 and 20 is 30" is stored // into buffer instead of printing on stdout printf("%s", buffer); return 0; } OutputSum of 10 and 20 is 30Time Complexity: O(n), where n is the number of elements being stored in buffer.Auxiliary Space: O(n), where n is the number of elements being stored in buffer. Comment K kartik Follow 54 Improve K kartik Follow 54 Improve Article Tags : C Language CPP-Library cpp-input-output Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C6 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like