any number of parameters. No limit!
zero or more it can be fixed or variable (printf is an example)
In C, the printf function uses a format string to determine how to display the arguments passed to it. The arguments are not specified with an ampersand (&) because printf requires the values of the variables, not their addresses. When passing variables to printf, their values are automatically accessed, which is why you simply provide the variable names without the address-of operator. This allows printf to correctly interpret and format the output based on the specified format string.
Not that difficult... int main (int argc, char **argv) { if (argc==1) printf ("No arguments\n"); else printf ("%d arguments\n", argc-1); goto END; END: return 0; }
# include<stdio.h> # include<conio.h> void main() { clrscr(); int a,b; printf ("Enter the first value:"); scanf ("%d",& a ); printf ("Enter the second value:"); scanf ("%d",& b ); printf ("\n\nBefor swaping the values "); printf ("\nThe first value is %d",a); printf ("\nThe second value is %d",b); printf ("\n\nAfter swaping the values "); printf ("\nThe first value is %d",b); printf ("\nThe second value is %d",a); }
== == What is printf in c or prototype of printf with example (q) What is prototype of printf function ? Explain each term. Ans: Prototype of printf function is : int printf( const char *format ,…) Explanation of each term : Parameter of printf function is : (three continuous dots) : It is called ellipsis. It indicates the variable number of arguments. Example of ellipsis: #include void ellipsis(int a,...); void main() { int a=5,b=10; clrscr(); ellipsis(a,b); getch(); } void ellipsis(int a,...) { printf("%d ",a); } Output:5 So printf function can have any number of variables as an argument.
zero or more it can be fixed or variable (printf is an example)
In C, the printf function uses a format string to determine how to display the arguments passed to it. The arguments are not specified with an ampersand (&) because printf requires the values of the variables, not their addresses. When passing variables to printf, their values are automatically accessed, which is why you simply provide the variable names without the address-of operator. This allows printf to correctly interpret and format the output based on the specified format string.
Not that difficult... int main (int argc, char **argv) { if (argc==1) printf ("No arguments\n"); else printf ("%d arguments\n", argc-1); goto END; END: return 0; }
Echo merely repeats its command line arguments as stated. The 'printf' command allows for formatted print and a more exacting method of printing out information. Printf requires you to specify the format of what you want to print; echo does not have this ability.
# include<stdio.h> # include<conio.h> void main() { clrscr(); int a,b; printf ("Enter the first value:"); scanf ("%d",& a ); printf ("Enter the second value:"); scanf ("%d",& b ); printf ("\n\nBefor swaping the values "); printf ("\nThe first value is %d",a); printf ("\nThe second value is %d",b); printf ("\n\nAfter swaping the values "); printf ("\nThe first value is %d",b); printf ("\nThe second value is %d",a); }
printf ("nested printf returned %d\n", printf ("inner printf\n"));
== == What is printf in c or prototype of printf with example (q) What is prototype of printf function ? Explain each term. Ans: Prototype of printf function is : int printf( const char *format ,…) Explanation of each term : Parameter of printf function is : (three continuous dots) : It is called ellipsis. It indicates the variable number of arguments. Example of ellipsis: #include void ellipsis(int a,...); void main() { int a=5,b=10; clrscr(); ellipsis(a,b); getch(); } void ellipsis(int a,...) { printf("%d ",a); } Output:5 So printf function can have any number of variables as an argument.
Too many arguments now = Too many arguments later
#include<stdio.h> main() { int i; for(i=1;i<=1;i++) { printf("*",i); } printf("\n"); for(i=1;i<=3;i++) { printf("*",i); } printf("\n"); for(i=1;i<=5;i++) { printf("*",i); } printf("\n"); for(i=1;i<=3;i++) { printf("*",i); } printf("\n"); for(i=1;i<=1;i++) { printf("*",i); } }
//program for myprintf using variable arguments #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <stdarg.h> int compare(const void * var1,const void * var2) { if(*(int *)var1 > *(int *)var2) { return(0); } else{ return(1); } } int myPrintf(const char * output ,...) { va_list arguments; int stringlength,stringIndx; char *s; int d; char c; stringlength = strlen(output); va_start(arguments,output); for(stringIndx = 0;stringIndx < stringlength;stringIndx++) { if(output[stringIndx] == '%') { stringIndx++; switch(output[stringIndx]) { case 's': /* string */ s = va_arg(arguments, char *); printf("%s\n", s); break; case 'd': /* int */ d = va_arg(arguments, int); printf("%d\n", d); break; case 'c': /* char */ default: /* need a cast here since va_arg only takes fully promoted types */ c = (char) va_arg(arguments, char); printf("%c\n", c); break; } } else{ printf("%c",output[stringIndx]); } } } void main() { unsigned int au32Nos[10] = {32,44.,55,66,11,8,9,7,9,10}; qsort(au32Nos,10,4,compare); myPrintf(" %d %d %d %d %d %d %d %d %d %d",au32Nos[0],au32Nos[1],au32Nos[2],au32Nos[3],au32Nos[4],au32Nos[5],au32Nos[6],au32Nos[7],au32Nos[8],au32Nos[9]); }
An arity is a number of arguments or operands a function or operation takes.
An arity is a number of arguments or operands a function or operation takes.