You are here:

C/return type

Advertisement


Question

hello sir

i would like to know what printf() or what scanf() functions returns. ya i know that i can see their prototypes in stdio.h but i m doing c programming in unix platform . i dont know how can i see the prototypes in header files

also the output of these programs
1.
int a;
a=printf("%d",a);

2.
int a;
a=printf("%d%c");

3.
int a,b;
a=scanf("%d%d",&a,&b);

give explanations to make it clear
thank you
monika

Answer
> i dont know how can i see the prototypes in header files
Search for printf() in stdio.h.
And your stdio.h file may be including some other file from where the prototype is coming.

I am using Solaris and I don't have printf() prototype in stdio.h!
But, stdio.h has:
#include <iso/stdio_iso.h>
So, if I grep this include this file, I get:
googol:temp> grep printf /usr/include/iso/stdio_iso.h
#pragma redefine_extname fprintf        _fprintf_c89
#pragma redefine_extname printf         _printf_c89
#pragma redefine_extname sprintf        _sprintf_c89
#pragma redefine_extname vfprintf       _vfprintf_c89
#pragma redefine_extname vprintf        _vprintf_c89
#pragma redefine_extname vsprintf       _vsprintf_c89
#define fprintf         _fprintf_c89
#define printf          _printf_c89
#define sprintf         _sprintf_c89
#define vfprintf        _vfprintf_c89
#define vprintf         _vprintf_c89
#define vsprintf        _vsprintf_c89
extern int      fprintf(FILE *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, ...);
extern int      printf(const char *_RESTRICT_KYWD, ...);
extern int      sprintf(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, ...);
extern int      vfprintf(FILE *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
extern int      vprintf(const char *_RESTRICT_KYWD, __va_list);
extern int      vsprintf(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
extern int      fprintf();
extern int      printf();
extern int      sprintf();
extern int      vfprintf();
extern int      vprintf();
extern int      vsprintf();
googol:temp>

So, you can see that printf() returns int.
And if you are using a Unix system, then you are very lucky!
You have all the man pages installed on your system.
Just do:
man printf
And it will print the complete manual and you can check the "Return Values" section there:-)

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.