Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Introduction to C++

C++ is a programming language created by Bjarne Stroustrup and his team at


Bell Laboratories in 1979. Forty years later, it is one of the most widely used
languages in the world; we can find C++ applications everywhere, from the
bottom of the oceans to the surface of Mars.

As the name implies, C++ was derived from the C language; Bjarne’s goal was
to add object-oriented programming into C, a language well-respected for its
portability and low-level functionality.

So why learn C++? Among many other things:

 It is fast and flexible.


 It is well-supported.
 It forces you to think in new and creative ways.

In this lesson, we’ll start learning some basic concepts, and you’ll write your
very first C++ program.

Note: Don’t worry if some words don’t make much sense right now. We’ll
learn about them in a bit!
Hello World!
Take a look at the hello.cpp file in the code editor that is placed in the middle
of the screen. It’s a C++ program!

In our code editor, the file name is displayed at the top:

C++ programs are stored in files which usually have the file extension .cpp,
which simply stands for “C Plus Plus”.

The code inside our C++ file is a classic first step all new programmers take —
they greet the world through the terminal!

The terminal is the black panel on the right. It should be blank right now. The
code in the text editor will print text out onto the terminal. More specifically, it
will print the phrase Hello World!.

Before we explain what all that mumbo jumbo is, let’s run the program to see
what happens.

Instructions

1.Press Run to see this program in action.


What message appeared in the terminal?
#include <iostream>

int main() {
  
  std::cout << "Hello World!\n";

Hello World!
Output:
Output
High five! We just got your first program to run.

C++, like most programming languages, runs line by line, from top to bottom.
Here is the structure of a C++ program:

In between the curly braces is what we are going to focus on for now.

std::cout << "Hello World!\n";

 std::cout is
the “character output stream”. It is pronounced “see-out”.
 << is an operator that comes right after it.
 "Hello World!\n" is what’s being outputted here. You need double quotes
around text. The \n is a special character that indicates a new line.
 ; is a punctuation that tells the computer that you are at the end of a
statement. It is similar to a period in a sentence.
Instructions

1.Let’s write the whole std::cout statement from scratch.


Inside the curly braces, type the following and press Run:

std::cout << "Codecademy\n";


What do you think this program will output?
#include <iostream>

int main() {
  
  
  
}

You might also like