We Will Discuss About First C Program
C is a popular programming language that is widely used for system programming, application development, and more. If you’re new to programming and want to learn C, the first step is to write your first C program. In this article, we will guide you through the process of writing your first C program.
Here's a classic first C program that prints "Hello, world!":
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
Explanation:
#include <stdio.h>
: This line includes the standard input/output header file, which provides functions likeprintf()
for printing output.int main()
: This is the main function of the program, where execution begins. Theint
return type indicates that the function returns an integer value.printf("Hello, world!\n");
: This line calls theprintf()
function to print the message "Hello, world!" to the console. The\n
character adds a newline.return 0;
: This line returns the value 0 to the operating system, indicating successful program execution.
How to Compile and Run:
- Save the code: Save the code as a
.c
file (e.g.,hello.c
). - Compile: Use a C compiler like GCC (GNU Compiler Collection) to compile the code:
This will create an executable file namedBashgcc hello.c -o hello
hello
. - Run: Execute the compiled program:
This will output:Bash./hello
Hello, world!
Key Points:
- The
main
function is the entry point of a C program. printf()
is used to print output to the console.- The
\n
character adds a newline to the output. - The
return 0;
statement indicates successful program execution.