Results 1 to 3 of 3

Thread: How to make a Hello World program in C/C++

  1. #1
    Join Date
    Oct 2014
    Beans
    3

    How to make a Hello World program in C/C++

    Hello there, it's Aaron, and I'm here to show you how to make a Hello World program in the C and C++ programming languages.

    First, go to the text editor of your choice, but personally, in my opinion, I recommend a IDE like Code::Blocks or even MonoDevelop (Which requires the Mono Runtime which you can get off Ubuntu Software Centre.) Then input this into the text editor window below. *NOTE IN C.

    Code:
    #include <stdio>
    
    int main(char argc, int argv[1])
    {
           printf("Hello World!\n");
    ; return 0;
    }

    Then save this as a .c in the folder of your choice.


    But if you want to make a hello world program in C++, however, which, in my opinion, I don't like very much.

    Repeat step 1, but this time, input the code below, instead of the code above:


    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
       std::cout << "Hello World" << std::endl;
    
    ; return 0;
    }
    This time, for step 3, save it AS A .CPP or it will not compile with GNU GCC or any compiler in general.


    Word of advice, I heavily suggest putting a semicolon both before and after the return statement, as compiling it without that will result in a error if you try to compile it and/or run it.


    Aaron out!!!!

  2. #2
    Join Date
    Apr 2012
    Beans
    6,187

    Re: How to make a Hello World program in C/C++

    What error do you get exactly if you remove the semicolon before the return statement?

    The arguments to `main` should have types

    Code:
    int main(int argc, char *argv[])
    I think. The first is a count of the arguments, and the second is a pointer to an array of character strings representing the arguments themselves.

    And shouldn't <stdio> be <stdio.h>?

    Also from the man pages, the recognized C++ extensions are

    Code:
           file.cc
           file.cp
           file.cxx
           file.cpp
           file.CPP
           file.c++
           file.C
               C++ source code that must be preprocessed.  Note that in .cxx, the
               last two letters must both be literally x.  Likewise, .C refers to
               a literal capital C.
    although in fact you can use any extension so long as you indicate the language using the -x option.

  3. #3
    Join Date
    Jul 2015
    Beans
    15

    Re: How to make a Hello World program in C/C++

    Does Code::Blocks have the same functions and features as DevC++ offers?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •