What are the different ways to print a string in the C language?

There are several main ways to print strings in the C language.

  1. Print the string “Hello, World!” using the printf function.
  2. Print the string using the puts function:
    puts(“Hello, World!”);
  3. Use the putchar function to print characters in a string one by one:
    char str[] = “Hello, World!”;
    int i;
    for (i = 0; i < strlen(str); i++) { putchar(str[i]); }
  4. Copy a string to a character array using the strcpy function, and then print the character array using the printf function:
    char str[50];
    strcpy(str, “Hello, World!”);
    printf(“%s”, str);
  5. Format the string into a character array using the sprintf function, and then print the character array using the printf function:

    char str[50];
    sprintf(str, “Hello, %s!”, “World”);
    printf(“%s”, str);

These are common ways to print strings, the specific choice depends on the specific requirements and scenarios.

bannerAds