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 4
In Progress

C++: Initializing and Declaring Variables

Yasin Cakal 5 Nov 2021
Lesson Progress
0% Complete

Now, moving on to the next steps, you don’t have to declare and initialize variables in different statements. There is a way to combine them in one statement. Suppose you are first declaring an int type variable marks and assigning it a value of 8.

For this, you will have to write two separate statements: int marks; and marks=8;. Let’s try and do it in one step. You can combine both of these statements into one by writing int marks = 8;. Here, you have first declared an int type variable marks and then assigned it a value 8 using an = operator. The statement ends with ;.

Things to Remember: You don’t have to declare a variable repeatedly before you use it. Even though you can combine both statements, it is best to declare all variables at the start, so it is easier to keep track of them and pull them into statements later.

Responses

Leave a Reply

%d bloggers like this: