Back to Course

Introduction to C++

0% Complete
0/0 Steps
  1. C++: Basics
    5Topics
    |
    6 Quizzes
  2. C++: Compilation and Execution
    5Topics
    |
    6 Quizzes
  3. C++: Variables
    9Topics
    |
    10 Quizzes
  4. C++: Conditions Operators
    5Topics
    |
    6 Quizzes
  5. C++: Logical Operators
    3Topics
    |
    4 Quizzes
  6. C++: Loops and Errors
    8Topics
    |
    9 Quizzes
  7. C++: Vectors
    4Topics
    |
    3 Quizzes
Lesson 3, Topic 2
In Progress

C++: Declaring Variables

Yasin Cakal 5 Nov 2021
Lesson Progress
0% Complete

You must declare a variable as a type before you use it.

Let’s suppose you want to create a list of students’ marks. For this, you will have to create a list of students’ names and input their marks in the int type variable. However, before we can use it, it has to be created and then declared as int type. To begin declaring, we need to follow a few steps.

  • Determign the type of variable you will be using, and
  • Name the variable.

To declare an int type variable named marks, write int marks;. int here is the type of variable you have declared and marks is the name of the variable. We add ; at the end to end the statement in C++.

Keep in mind, names of variables can be stored in letters (uppercase or lowercase), underscores, and/or digits.

Things to Remember: Do not declare a variable as a wrong variable type. This can give you errors, warnings, and wrong outputs.

Responses

Leave a Reply

%d bloggers like this: