Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare printf()?

Tags:

c

printf

I wanted to print something using printf() function in C, without including stdio.h, so I wrote program as :

int printf(char *, ...);
int main(void)
{
        printf("hello world\n");
        return 0;
}

Is the above program correct ?

like image 619
Happy Mittal Avatar asked Nov 14 '10 18:11

Happy Mittal


People also ask

How printf function is written?

1 C standard output (printf(), puts() and putchar()) The printf() function sends a formatted string to the standard output (the display). This string can display formatted variables and special control characters, such as new lines ('\n'), backspaces ('\b') and tabspaces ('\t'); these are listed in Table 2.1.

What Is syntax of printf () statement?

printf() function It prints the given statement to the console. The syntax of printf() function is given below: printf("format string",argument_list);

Where is printf declared?

printf is a function which is defined in stdio. h header file. It will print everything to the screen which is given inside the double quotes.

What is printf () in Java?

The printf function (the name comes from “print formatted”) prints a string on the screen using a “format string” that includes the instructions to mix several strings and produce the final string to be printed on the screen.


2 Answers

The correct declaration (ISO/IEC 9899:1999) is:

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

But it would be easiest and safest to just #include <stdio.h>.

like image 61
CB Bailey Avatar answered Oct 08 '22 06:10

CB Bailey


Just:

man 3 printf

It will tell you printf signature:

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

this is the right one.

like image 35
peoro Avatar answered Oct 08 '22 06:10

peoro