== == 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.
We use the printf function to display the output on the screen....
and if u have writtten a program and executed it with no errors then how u'll see the output ?but just coz of the printf statement
printf is used to display the output of a program
function, just like scanf, system, read, malloc etc.
No it is a pre-defined function from the library.
That is why it includes a pair of paranthesis.
Eg: printf("This is the answer");
It's a function that print (something) on the terminal
it's like (cout) function.
Scanf and printf both functions are inbuilt in C language. Scanf is used to read a string. Printf is used to print something.
Neither is printf, stderr or NULL. Certainly, they are important words, but not keywords.
Anything that you can't put whitespace between. The indivisible elements of a program. Example: printf("Sup world %d",variable); Tokens: (7 total) printf ( "Sup World %d" , variable ) ;
#include#include#includevoid keyw(char str[10]){if(strcmp("for",str)==0)printf("%s is a keyword",str);else if(strcmp("while",str)==0)printf("%s is a keyword",str);else if(strcmp("char",str)==0)printf("%s is a keyword",str);else if(strcmp("int",str)==0)printf("%s is a keyword",str);else if(strcmp("if",str)==0)printf("%s is a keyword",str);else if(strcmp("else",str)==0)printf("%s is a keyword",str);elseprintf("%s is an identifier",str);printf("\n");}main(){FILE *f1,*f2,*f3;char c,str[10];int num[100],ln=0,tvalue=0,i=0,j=0,k=0;printf("Enter a C program expression");f1=fopen("input.c","w");while((c=getchar())!=EOF)fputc(c,f1);f1=fopen("input.c","r");f2=fopen("identifier.txt","w");f3=fopen("specialchars.txt","w");while((c=fgetc(f1))!=EOF){if(isdigit(c)){tvalue=c-'0';c=fgetc(f1);while(isdigit(c)){tvalue=tvalue*10+c-'0';c=fgetc(f1);}num[i++]=tvalue;ungetc(c,f1);}else if(isalpha(c)){fputc(c,f2);c=fgetc(f1);while((isdigit(c))isalpha(c)c==' 'c=='$'){fputc(c,f2);c=fgetc(f1);}fputc(' ',f2);ungetc(c,f1);}else if(c==' 'c=='\t');else if(c=='\n')ln++;elsefputc(c,f3);}fclose(f1);fclose(f2);fclose(f3);printf("Numbers in the program are \n");for(j=0;j
#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); } }
#include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[8];int s,i,flag=0,loc1=0,loc2=0,j; clrscr(); printf("Enter any string\n"); gets(a); for(i=0;i<8;i++) { int ch=a[i]; if(ch!=32) { loc2=i; flag++; } if(ch==32) { s=flag; flag=0; switch(s) { case 2: if(a[loc1]=='i' && a[loc2]=='f') printf("STRING HAS if AS A KEYWORD"); break; case 3: if(a[loc1]=='f' && a[loc1+1]=='o' && a[loc2]=='r') printf("STRING HAS for AS A KEYWORD"); break; default: printf("not our case"); } } } getch(); }
Neither is printf, stderr or NULL. Certainly, they are important words, but not keywords.
It is 'sizeof'. Example: printf ("sizeof(int)=%d\n", sizeof (int));
Anything that you can't put whitespace between. The indivisible elements of a program. Example: printf("Sup world %d",variable); Tokens: (7 total) printf ( "Sup World %d" , variable ) ;
#include#include#includevoid keyw(char str[10]){if(strcmp("for",str)==0)printf("%s is a keyword",str);else if(strcmp("while",str)==0)printf("%s is a keyword",str);else if(strcmp("char",str)==0)printf("%s is a keyword",str);else if(strcmp("int",str)==0)printf("%s is a keyword",str);else if(strcmp("if",str)==0)printf("%s is a keyword",str);else if(strcmp("else",str)==0)printf("%s is a keyword",str);elseprintf("%s is an identifier",str);printf("\n");}main(){FILE *f1,*f2,*f3;char c,str[10];int num[100],ln=0,tvalue=0,i=0,j=0,k=0;printf("Enter a C program expression");f1=fopen("input.c","w");while((c=getchar())!=EOF)fputc(c,f1);f1=fopen("input.c","r");f2=fopen("identifier.txt","w");f3=fopen("specialchars.txt","w");while((c=fgetc(f1))!=EOF){if(isdigit(c)){tvalue=c-'0';c=fgetc(f1);while(isdigit(c)){tvalue=tvalue*10+c-'0';c=fgetc(f1);}num[i++]=tvalue;ungetc(c,f1);}else if(isalpha(c)){fputc(c,f2);c=fgetc(f1);while((isdigit(c))isalpha(c)c==' 'c=='$'){fputc(c,f2);c=fgetc(f1);}fputc(' ',f2);ungetc(c,f1);}else if(c==' 'c=='\t');else if(c=='\n')ln++;elsefputc(c,f3);}fclose(f1);fclose(f2);fclose(f3);printf("Numbers in the program are \n");for(j=0;j
printf ("nested printf returned %d\n", printf ("inner printf\n"));
#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); } }
#include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[8];int s,i,flag=0,loc1=0,loc2=0,j; clrscr(); printf("Enter any string\n"); gets(a); for(i=0;i<8;i++) { int ch=a[i]; if(ch!=32) { loc2=i; flag++; } if(ch==32) { s=flag; flag=0; switch(s) { case 2: if(a[loc1]=='i' && a[loc2]=='f') printf("STRING HAS if AS A KEYWORD"); break; case 3: if(a[loc1]=='f' && a[loc1+1]=='o' && a[loc2]=='r') printf("STRING HAS for AS A KEYWORD"); break; default: printf("not our case"); } } } getch(); }
void main() { int a,b,c; clrscr(); printf("Enter the value of a:"); scanf("%d",&a); printf("\nEnter the value of b:"); scanf("%d",&b); printf("\nEnter the value of c:"); scanf("%d",&c); if(a>b) { if(a>c) { if(b>c) { printf("c is smallest\n"); printf("b is middle\n"); printf("a is largest\n"); } else { printf("b is smallest\n"); printf("c is middle\n"); printf("a is largest\n"); } } else { printf("b is smallest\n"); printf("a is middle\n"); printf("c is largest\n"); } } else if(b>c) { if(a>c) { printf("c is smallest\n"); printf("a is middle\n"); printf("b is largest\n"); } else { printf("a is smallest\n"); printf("c is middle\n"); printf("b is largest\n"); } } else { printf("a is smallest\n"); printf("b is middle\n"); printf("c is largest\n"); } getch(); }
Printf function is used in c language. Printf is used to print something to the standard output. ex: printf ('welcome');
Try this: #include <stdio.h> int main (void) { printf ("printf is at location %p\n", (void *)printf); printf ("main is at location %p\n", (void *)main); return 0; }
void print_num_as_word (unsigned num) { switch (num) { case 0: printf ("zero"); break; case 1: printf ("one"); break; case 2: printf ("two"); break; case 3: printf ("three"); break; case 4: printf ("four"); break; case 5: printf ("five"); break; case 6: printf ("six"); break; case 7: printf ("seven"); break; case 8: printf ("eight"); break; case 9: printf ("nine"); break; } }
main() { if( !fork() ) printf("Hello"); else printf("World"); } This works fine. if (!printf("hello")) printf("Hello"); else printf(" World\n");