int printf(const char *format, ...);
Why printf can receive more than 2 arguments although there is no overloading in c.
Anyone can give me some brief explanation the use of ...(3 dots) in printf function argument?![]()
This is a discussion on printf function explanation within the C Programming forums, part of the General Programming Boards category; int printf(const char *format, ...); Why printf can receive more than 2 arguments although there is no overloading in c. ...
int printf(const char *format, ...);
Why printf can receive more than 2 arguments although there is no overloading in c.
Anyone can give me some brief explanation the use of ...(3 dots) in printf function argument?![]()
... in the parameter list means that 0 or more arguments could be passed. You access these arguments with the stdarg.h functions.
Code:#include <stdio.h> #include <stdlib.h> #include <stdarg.h> void myprintf(const char* lpszText, ...) { va_list args; char szMessage[256]; va_start(args,lpszText); vsprintf(szMessage,lpszText,args); va_end(args); fputs(szMessage,stdout); } int main(void) { myprintf("The numbers are %d and %d\n",5,1); return EXIT_SUCCESS; }
lpszThisIsMyFormatString. i like that.
vice, you need to read a book.
"The C programming Language" by Kernighan & Ritchie,
chapter 7.3, "Variable-length Argument Lists"
thanks for the explanation