404 - Content Not Found

Note: If content is not found, please visit the homepage for more updates.

Go to Homepage

First Program in C

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:

  1. #include <stdio.h>: This line includes the standard input/output header file, which provides functions like printf() for printing output.
  2. int main(): This is the main function of the program, where execution begins. The int return type indicates that the function returns an integer value.
  3. printf("Hello, world!\n");: This line calls the printf() function to print the message "Hello, world!" to the console. The \n character adds a newline.
  4. return 0;: This line returns the value 0 to the operating system, indicating successful program execution.

How to Compile and Run:

  1. Save the code: Save the code as a .c file (e.g., hello.c).
  2. Compile: Use a C compiler like GCC (GNU Compiler Collection) to compile the code:
    Bash
    gcc hello.c -o hello
    
    This will create an executable file named hello.
  3. Run: Execute the compiled program:
    Bash
    ./hello
    
    This will output:
    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.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!