Skip to main content
Engineering LibreTexts

1.11: C++ Examples

  • Page ID
    10590
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    306px-ISO_C_Logo.svg_.pngOverview

    C++ is a general-purpose programming language. It has imperative, object-oriented and generic programming features, while also providing facilities for low-level memory manipulation. C++ was developed by Bjarne Stroustrup at Bell Labs starting in 1979 as an extension of the C language. The C++ programming language was initially standardized in 1998.[1]

    C++ is one of the most popular current programming languages[2] and is often used in computer science courses.

    Example

    Hello World

    // This program displays "Hello world!"
    //
    // References:
    // http://www.cplusplus.com/doc/tutorial/program_structure/
    
    #include <iostream>
    
    int main()
    {
        std::cout << "Hello world!";
    }

    Output

    Hello world!
    

    Discussion

    Each code element represents:[3]

    • // begins a comment
    • #include <iostream> includes standard input and output streams
    • int main() begins the main function, which returns an integer value
    • { begins a block of code
    • std::cout is standard output
    • << directs the next element to standard output
    • "Hello world!" is the literal string to be displayed
    • ; ends each line of C++ code
    • } ends a block of code

    C++ IDEs

    There are many free cloud-based and local IDEs available to begin coding in C++. Check with your instructor or do your own research for recommendations.

    Local IDEs

    • Code::Blocks
    • Dev-C++
    • Microsoft Visual Studio

    References

    • Wikiversity: Computer Programming

    1. Wikipedia: C++
    2. TIOBE: Index
    3. Wikibooks: Programming Fundamentals/Hello World

    1.11: C++ Examples is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?