The syntax for printf is:
int printf(const char *format, ...);
Simple usage examples:
1. Print character literal: printf("%c", 'a');
2. Print character variable: printf("%c", my_char);
3. Print string literal: printf("%s", "hello world");
4. Print string variable: printf("%s", my_string);
5. Print integer variable: printf("%d", my_integer);
6. Print floating-point variable: printf("%f", my_float);
printf() is used to print a formatted string to the standard output.
It's usage is af follows:
"printf(const char * format, ...)"
where 'format' is a string to be printed to the standard output, optionally containing format tags that will be replaced by the arguments that follow (...).
Example:
...
char *name = "Alice";
printf("Hello there, %s!\n", name);
output:
Hello there, Alice!
'%s' was replaced with the contents of the variable 'name' (Alice).
Please see the documentation for a full list of format tags and usage.
The printf function formats data in the form of strings, integers, floating-point numbers, characters, and pointers, and sends it to the standard output stream.
Printing formatted data.
A main function must be present in every C program.
== == 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.
Every C plus plus program that is a main program must have the function 'main'.
#include <stdio.h> void main() { int a,b,c,i,j; printf("Enter the number of rows for square matrix : "); scanf("%d",&a); for(i=1;i<=a;i++) { for(c=1,j=1;j<=a;j++,c++) { if(c==i) printf("1 "); else printf("0 "); } printf("\n"); } getch(); }
It is a function.
int main() { // Call the printf function printf("This is a function call!\n"); return 0; }
Basic Program in "C" #include <stdio.h> /*This is the standard input/output library function*/ main(void) /*All C programs must have the function main*/ { char ch; printf("This is a C Program."); /* Every line of code in C must end with a semi colon*/ printf("Welcome to C!");/*the printf outputs the line of text to the screen*/ scanf("%c%c", &ch, &ch); /* This is a trick way to pause the computer so you can read the information on the screen*/ return 0; /* Indicates that your program has terminated successfully*/
void main() { printf("followiing"); }
A C program #include <stdio.h> int main() { printf("Hello, world!"); }
A main function must be present in every C program.
main() { if(printf("%c",59)) }
if you do not used main function in c program when errors are accrued
Here is an example:#include int main (void){puts ("Hello, world");return 0;}
Printf function is used in c language. Printf is used to print something to the standard output. ex: printf ('welcome');
You cannot create a program with the extension .exe without the function main. You can create a dll which does not even use main. WinApi uses another main function but it's still a main function. Main function is entry point for your program, no entry point no program.Write a progrmme in c with out using a main function. #include #define decode(s,t,u,m,p,e,d)m##s##u##t #define begin decode(a,n,i,m,a,t,e) int begin() { printf("HELLO") }
#include#includevoid main(){ int a,b,c;printf("\nEnter 1st no.");scanf("%d",&a);printf("\nEnter 2nd no.");scanf("%d",&b);c=a;a=b;b=c;printf("\n1st no.",a);printf("\n2nd no.",b);getch();}
Into the source program.