Write, compile and run a program that displays the following lines:

O Cameroon thou cradle of our fathers
...
Thy welfare we will win in toil and love and peace

Source Code

Brief explanation is provided after the source code.

#include <stdio.h>

int main(int argc, char ** argv) {
    printf("O Cameroon thou cradle of our fathers\n");
    printf("...\n");
    printf("Thy welfare we will win in toil and love and peace\n");
    return 0;
}

When you compile and execute the above program it produces the following result on Linux:

O Cameroon thou cradle of our fathers
...
Thy welfare we will win in toil and love and peace

Brief Explanation

  • This program makes use of the printf function to display the necessary information. printf is a library function that prints output, in this case the string of characters between the quotes.
  • \n is an escape sequence for newline. This makes the output to be displayed on separate lines.
  • A return value of zero implies normal termination; non-zero values signal unusual or erroneous termination conditions.
  • The first line of the program, #include tells the compiler to include information about the standard input/output library.
  • The main function takes two arguments. The first (conventionally called argc, for argument count) is the number of command-line arguments the program was invoked with; the second (argv, for argument vector) is a pointer to an array of character strings that contain the arguments, one per string. We customarily use multiple levels of pointers to manipulate these character strings.
  • Since we are not passing any command-line arguments in this program, the main function could be written without those arguments. (int main(){})

Add comment


Security code
Refresh