TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    C Tutorials

    Compile & Run a C Program on Linux

    Overview

    In this tutorial, we will learn the steps involved to compile and run a C Program from the command line on a Linux machine.

    Steps to install GNU C/C++ compiler:

    https://www.testingdocs.com/install-gcc-c-compiler-on-opensuse/

    C Program

    Create a hello.c file. We can use the file manager to create the file.

    To create a file from the Command-line:

    $ touch hello.c

    or

    $ vi hello.c

    Open the C source code file in the text editor like vi, emacs, gedit, Kate, etc based on the Linux environment.

    Write the C program source code by editing a file.

    /******************************************** 
     * File:hello.c
     * Sample C Program on Linux 
     * Compile and Run from command line demo.
     * C Tutorials - www.TestingDocs.com
     ********************************************/
    // header files
    #include<stdio.h>
    #include<stdlib.h>
    
    // main function
    int main()
    {
     printf("Hello World! \n"); // print Hello message
     exit(EXIT_SUCCESS);
    }

    C Program Hello Linux Kate Editor

    Compile

    Let’s compile the C program. The gcc compiler produces an executable output file called a.out.

    $ gcc hello.c

    a.out is the default output executable file created when no output name is specified. We can specify the output file name with -o switch

    $ gcc hello.c -o hello

    Compile and Run C Program Linux

    Run a C Program

    Let’s run the C program with the default a.out executable output file.

    $ ./a.out

    Compile C Program Default Linux

    To run the output file, for example, hello:

    $ ./hello

    This should print the Hello World! message to the terminal screen.

    That’s it.

    Related Posts

    C Language Characteristics

    C Tutorials /

    C Language Characteristics

    C Source Code .c File

    C Tutorials /

    C Program Files & Formats

    GNU Compiler Collection GCC

    C Tutorials /

    C Compilers

    C Pointers

    C Tutorials /

    C Pointers

    C Tutorials /

    C Two-Dimensional Arrays

    ‹ C Array Syntax› Programming Language Translators

    Recent Posts

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com