EmbLogic's Blog

Difference Between printf() and scanf() in C

printf():

  • When printf() is used in a progam,that means whatever statement we want to print on the shell will be written inside the double codes i.e printf(“hello”).
  • If we write printf(“Hello\n”) then \n means when Hello is printed on the shell then cursor will move to the very next line of the shell.
  • Another eg is if we have already assigned a value to a variable i.e int a=7,and we want to printf the value of a using printf(),we will write as printf(“value of a=%d”,a); Here %d means assigning the very next integer.And it will print as “value of a=7″ on the shell.And there is no need to give the address.
  • printf() returns the number of bytes written succesfully.

scanf():

  • If we want that the user will enter some value then we use scanf().For eg scanf(“%d”,&a),here address is given in the scanf() so that some address is allocated to the integer.
  • scanf() does not return anything.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>