Writing and Running Your First C Program ("Hello, World!")

Sanu Faujdar
0

Writing and running your first C program, often referred to as the "Hello, World!" program, is a simple yet essential step in learning C programming. Here's a step-by-step guide on how to do it:

  1. Install a C Compiler: Before you can write and run a C program, you need a C compiler. If you are using a Linux-based system, you probably already have one installed (e.g., GCC). If you're using Windows, you can use a compiler like MinGW or install an Integrated Development Environment (IDE) like Code::Blocks or Dev-C++. Alternatively, you can use an online C compiler for a quick start.

  2. Open a Text Editor: You can use any text editor to write your C program. Common choices include Notepad (Windows), Visual Studio Code, Sublime Text, and Vim (Linux), or any code-specific IDE like Code::Blocks or Dev-C++.

  3. Write the C Program: In your text editor, write the following simple C program:

    c#include <stdio.h>
    
    int main() {
        printf("Hello, World!\n");
        return 0;
    }
    

    This program includes the standard I/O library <stdio.h and defines a main() function. Inside the main() function, it uses the printf function to display the "Hello, World!" message and then returns 0 to indicate successful execution.

  4. Save the Program: Save your C program with an .c extension. For example, you can save it as hello.c.

  5. Compile the Program: Open a command prompt or terminal, navigate to the directory where you saved your C program, and compile it using your C compiler. If you're using GCC on the command line, you can compile the program like this:

    gcc hello.c -o hello
    

    This command tells GCC to compile hello.c and generate an executable named hello. The -o flag specifies the output file name.

  6. Run the Program: After successfully compiling the program, you can run it by entering:

    bash./hello
    

    If you're on Windows and using MinGW, you can just type hello without the ./.

  7. Output: You should see the output on the screen:

    Hello, World!
    

Congratulations! You have just written and run your first C program. The "Hello, World!" program is the simplest C program and serves as a great starting point for learning the C programming language. You can build on this foundation to create more complex programs and explore the rich features of the C language.

Tags

एक टिप्पणी भेजें

0टिप्पणियाँ

एक टिप्पणी भेजें (0)