Learn C++: Variables

Learn C++ variables and data types.

Start[missing "en.views.course_landing_page.learn-c-plus-plus.course_illustration" translation]
Variables
Lesson 1 of 1
  1. 1

    The "Hello, World!" program just writes to the screen. It does not read anything and it doesn't calculate anything. That's no fun! Real programs tend to produce results based on some input that the...

  2. 2

    "Every variable in C++ must be declared before it can be used!" Before you can use a variable, you need to declare, or create, it. To declare a variable, you must provide two things: - A data...

  3. 3

    After you declare a variable, you can give it a value! Suppose that you have an [...] variable called [...] , to set it to 0: [...] - The [...] is the name of the variable. - The [...] ...

  4. 4

    You can both declare and assign a value to a variable in a single initialization statement. Suppose we have these two lines: [...] We can actually combine these two lines into a single line o...

  5. 5

    Computers are incredible at doing calculations. Now we have declared variables, let's use them and arithmetic operators to calculate things! Here are some arithmetic operators: - [...] additi...

  6. 6

    Now that we have outputted a variable and have also outputted things using multiple [...] s. Let's take a closer look at [...] again. If we have the code below: [...] It will output: [.....

  7. 7

    Like we mentioned in the introduction, another way to assign a value to a variable is through user input. A lot of times, we want the user of the program to enter information for the program. We h...

  8. 8

    Now that we've learned about the basics of variables and [...] , let's write a program! The mad scientist Kelvin has mastered predicting the weather in his mountain-side meteorology lab. Recentl...

  9. 9

    Let's go back to the temperature.cpp that we wrote. This time, instead of giving [...] a value of the current temperature in New York: [...] Let's ask the user what the temperature is usi...

  10. 10

    You made it to the end of this lesson! High five! Here is a review of the lesson: - A variable represents a particular piece of your computer's memory that has been set aside for you to use to...

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo

Learn C++: Variables

Start[missing "en.views.course_landing_page.learn-c-plus-plus.course_illustration" translation]