Easy Tutorial: Computer Programming

Computer programming is a very useful tool. A lot of people don't have much of a knowledge on it at all. High schools don't really teach much of it (at least mine sure didn't). I will show you how to write the most basic program you can write. This tutorial will be in C++. This language was derived from C. These are both very popular programming languages. I will also show you what this program looks like in other languages.

STEP 1: Writing the program

The following program is called "Hello World." All this program will do, is put "Hello World" on your screen. Make a text file, and rename it hello.c (or anythingyouwant.c). First, I will show you what to put in that file, then explain what each line means.

  • #include.... (I can't get around Markdown)
    • This accesses the library called iostream. Programming languages have many libraries with built in functions that you can use. In plain English, the people who created C++ already programmed these functions for you to use. iostream contains input and output functions (put stuff on your screen, take stuff off of your screen).
  • using namespace std;
    • Instead of being able to use cout << ; we would have to use std::cout << ;
    • It has to do with function prefixes.
  • int main()
    • this line declares the function main()
    • main() is where the program looks at first. This is how it knows where to start.
    • int declares the function type (integer).
  • {brackets}
    • brackets are placed at the beginning and the end of a function so that the program can see exactly what is in each function.
  • cout << "Hello World!" << endl;
    • cout << is a function that displays something on your screen.
    • "Hello World!" - obviously, this is what you want to appear on the screen. This is in the form of a string of characters. You must put quotes around it.
    • << endl; - this puts a new line on the screen after the text. You can also put "\n" inside the quotes with the "Hello World!" It does the same thing.
  • return 0;
    • This just tells the function main() to return the value 0 (remember, it was type 'int').
  • semicolons
    • The semicolons tell the program when a line is over.
    • Spaces and new lines mean nothing to the program. You can write an entire program on one line.

So that is how to write a Hello World program in C++.

STEP 2: Compiling and running the program.

First, you need a compiler on your system. For C++, g++ is the compiler. You can download programs with built in compilers (Cygwin is one for Windows). I have access to my college's Linux system, so I will be using that.

On your command line, type in the command g++ hello.c (or whatever you named your file -- also, you have to be in the same directory...). It should compile. If an error comes up, you did something wrong. after that, there will be an executable file called a.out. Type in the command ./a.out. This will run your program.

If you are confused on how to get g++, or unsure what program to get, leave a comment.

Congratulations! You ran your first program!

Here are some Hello Worlds in other languages:

C:

Java:

Sort:  

I'm going to be following these tutorials! Keep it up, I'll vote up each one.

Thanks a lot man! Leave as many suggestions as you want!

Thanks for this tutorial. I am interested in computer programming.

It is really cool, but it is a pain in the ass every once in a while.

Coin Marketplace

STEEM 0.19
TRX 0.13
JST 0.030
BTC 62855.38
ETH 3444.80
USDT 1.00
SBD 2.51