What is the return type of the printf and scanf functions ?1) void2) float3) int4) any

Int

Questions by ashish1287

Showing Answers 1 - 20 of 20 Answers

baseersd

  • Jul 27th, 2007
 

Hi Ashish,

The return type of printf() and scanf() is int

In the declaration, observe the return type is int.

int printf(const char *format, ...);
int scanf( const char *format, ... );


printf() returns the number of charecters printed on the console
scanf() returns the number of variables to which you are provding the input.

The following example will give u the clear idea.

#include<stdio.h>

int main()
{
    int i,j;
    printf("nPrinted %d charecters on stdoutn ",printf("Enter values of i & j"));
printf("nYou entered input for %d variables",scanf("%d %d",&i,&j));
  getch();  
}


Tanka

  • Jul 13th, 2011
 

#include
int main()
{
char i;
printf("
%c
",scanf("%c",&i));
return 0;

}
Given piece of code gives no output when we give character e as input.
why is it so??

 

Code
  1. #include<stdio.h>

  2.  

  3. int main()

  4. {

  5.   char i;              

  6.         printf("

  7. %c

  8. ",scanf("%c",&i));

  9. return 0;

  10.  

  11. }

  Was this answer useful?  Yes

Tanka

  • Jul 13th, 2011
 

The given piece of code gives no output when a character is provided as input. Why is it so?

 

Code
  1. #include<stdio.h>

  2.  

  3. int main()

  4. {

  5.   char i;              

  6.         printf("

  7. %c

  8. ",scanf("%c",&i));

  9. return 0;

  10.  

  11. }

snehal salunkhe

  • Sep 7th, 2015
 

The return type for printf() and scanf() is integer.

  Was this answer useful?  Yes

Anil kumar

  • Jan 22nd, 2016
 

Return type of both of them is integer. Scanf returns how many things it has read while printf returns how many characters get printed.

  Was this answer useful?  Yes

prathmesh dhumal

  • May 9th, 2017
 

Return type of printf is int

Code
  1. * whitespace character also calculated*

  2. #include<stdio.h>

  3. #include<conio.h>

  4. void main()

  5. {

  6. printf("%d" , printf("%s" , "welcome in c"));

  7. getch();

  8. }

  9. output is 12

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions