print vs printf in C
In the C programming language, the functions print and printf are different, with the following distinctions:
- The print function is a macro in the C language used to print text information to the standard output stream (stdout). It can only print strings and does not support formatted output. The usage of print is as follows:
- #include
int main() {
printf(“Hello, World!\n”);
return 0;
} - Output result:
- Greetings, Earth!
- printf: printf is a function in the C language standard library stdio.h, used for formatting text output. It can print various types of data and supports format specifiers. The usage of printf is as follows:
- #include
int main() {
int number = 10;
printf(“The number is %d\n”, number);
return 0;
} - Output result:
- The number equals 10.
In summary, print is just a macro for printf, used to simplify the use of printf, can only print strings, and does not support formatted output; while printf is a function that can print various types of data and supports format control characters.