![]() |
VOOZH | about |
In this article, we will learn how to implement your own custom printf() function in C language.
The printf() function is present in <stdio.h> header and uses a const char* and variable length arguments as its parameters. Hence we would be using <stdarg.h> header file which provides operations available on variable arguments passed to a function.
Prerequisites:Variadic Functions in C, Strings in C
Example Outputs:
Code 1: myprintf("Hello world %i",404);
Output: Hello world 404.
Code 2: char s[]="Multiverse is real";
myprintf("%s Hello %.3f",s,2.3);
Output: Multiverse is real Hello 2.30
Integer: 10 String: GeeksforGeeks Float: 12.25
The time complexity of the above code is: O(n * L), where,
In most practical cases, the time complexity is O(1).
Must Read - printf() in C