print vs printf in C

In the C programming language, the functions print and printf are different, with the following distinctions:

  1. 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:
  2. #include

    int main() {
    printf(“Hello, World!\n”);
    return 0;
    }

  3. Output result:
  4. Greetings, Earth!
  5. 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:
  6. #include

    int main() {
    int number = 10;
    printf(“The number is %d\n”, number);
    return 0;
    }

  7. Output result:
  8. 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.

bannerAds