First C Program

Here's a simple example of a C program that prints "Hello, World!" to the console using the void keyword in the main function. This example demonstrates the basic structure of a C program.

Example:

#include <stdio.h>

void main() {
    printf("Hello, World!\\n");
}

Output:

Hello, World!

Explanation:

1. #include <stdio.h>: This line includes the standard input-output library, which is necessary for using the printf function.

2. void main(): This defines the main function of the program, where void indicates that the function does not return a value. Note that using void as the return type for main is not standard-compliant; the standard return type for main is int. However, using void is sometimes seen in simple programs or older code.

3. printf("Hello, World!\n");: This line prints the string "Hello, World!" followed by a newline character (\n) to the console

Note:

Although the above example uses void main() to keep it simple, it is generally recommended to use int main() and return a value at the end of the function to adhere to the C standard. Here's the standard-compliant version:

#include <stdio.h>

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

In this version:

int main(): The main function returns an integer value.

return 0;: Indicates that the program executed successfully.