 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you the comparison between printf and sprintf functions. Before starting, you can subscribe my YouTube channel by clicking on the link which is available at the bottom right corner of this video. You can download my app Techimage that is available on Google Play. You can connect with me by following these details which are available in front of you. In this video, we will see the use of printf and sprintf functions which are available in C. So I am including a header file stdi.h because it contains both the functions. Then I am defining main function. Inside main function, first I am calling printf. This printf is containing a text hello friends. So I am first executing this code. You can see hello friends is displayed on console with the help of printf. Now I am declaring a string and its size is 10. Now I am using sprintf then str and I am assigning content Sanjay here. I am increasing its size to 20. So you can see first printf statement is containing only one argument hello friends and sprintf is containing two arguments. First one is str and second one is string which is enclosed in double quotes. So in sprintf this Sanjay here will be assigned into str. Now if I want to check whether it is assigned into str or not then I have to use this protest function to display the contents which are available inside str. So this time hello friends and Sanjay here both the outputs will be displayed on console. You can see here hello friends Sanjay here both are displayed on console. So I hope you have understood the difference between printf and sprintf. Printf displays displays the contents on console directly whereas sprintf stores the contents into a string and then you can use protest or another printing functions to display the contents which are available inside string. So if you want to display the content directly on console use printf if you want to store the output into a string then you can use sprintf. We can use these functions with integer float and characters also. So I am declaring an integer variable n which is having 10 float variable f which is having value 20.5 and character array s which is containing name of my country that is India. Now I will be using printf and sprintf functions to demonstrate use of these functions with these three kind of variables. So first time using integer so I am modifying this printf. You can see printf is containing first argument output equals to percent d and then n. Now sprintf I have to modify it also this is the statement of sprintf it has three arguments str then output equals to percent d and then n. So in case of printf output will be directly displayed on console but in case of sprintf this output equals to percent d and percent d will be replaced by value of n will be assigned into str. And then we have to use put s to display the string on console. Now again I am executing this you can see the output output equals to 10 and output equals to 10 both are displayed on console. So I hope you have understood we can use printf and sprintf with variables also both are working differently. Now you can use float variable as well like this this time output equals to percent f because I am using float values that's why I am using percent f percent f and variable is f. So again I am executing this code you can see the output both are printing same results but printf is directly printing on console. Whereas sprintf is storing the result into str and through put s I am displaying the result on console. Similar to this I am using s and to printing it I am using percent s. You can see output equals to India output equals to India is displayed on console. So friends I hope you have understood the difference between printf and sprintf functions. One is directly displaying the contents on console whereas second one is storing the contents into a string and then you can display or you can use that string for another purpose. I hope you have understood the difference well if you want to watch more programming related videos you can connect with me and you can subscribe my YouTube channel. Thank you for watching this video.