Variables and Constants

Variables and Constants:

What is a variable?

Visual Understanding


1. It is an alphabet or some string to which we assign some value and make use of it in our program according to our requirement.

2. It changes according to our requirement.

· Example: I have a variable say m = 1 and I can also have n = 1.

3. Embedded spaces between the variables is not allowed because the compiler will not consider the variable with spaces in between.

· We have cap I = 1 this is not considered it can be capI = 1.

4. In the above example we have a numerical value which is fixed for both the variables.

What is constant?

1. In the above example we have a number which is and so called constant.

2. Constants are the numbers or values that do not change if they are once fixed to any variable.

3. Same case with the constants also where embedded spaces are not considered because they are numbers, and no space is given.

· Example: x = 1 and y = 1.

· x = 1 and y = 1 constants are fixed.

Example:

//Addition of two numbers..

What are Comments and what is the role of it?

· Comments are some sentences written before we start to code for a single line or it maybe for the whole code.

· They are ignored by the compiler it is only for the user to manipulate data and access it in any time required.

· It provides us the following advantages:

1. Enhances the readability of the code.

2. Save our time.

3. Third-party access is also easy.

We have two types of comments:

One of it is / * which will be marked at the beginning.

· And the other is by using // character.

Usage of / and *:

This indicates the beginning of our code.

They are referred as multi-line comment.

To end our comment we use * / .

Example: /**** This is my daily blogger stay tuned for updates ****/

Here my sentences are enclosed in the multi-line comment this helps anyone referring my code or statements to understand easily without any complications.

Usage of // comment:

This comment can be declared line wise while we code.

They are known as single-line comment.

To declare some statement or assign value to a variable.

Example: x = 2; //Assigning x to be 2.

Using comment makes easy to understand what is that specific line is indicating.

In other words, we can say to manipulate our given data we use comments.

******But over usage also degrades the data.******

So comments must be used efficiently and smartly..

Scroll to top