# Variables in Programming and Algebra

Now that you know what a variable is, we will clarify a common area of confusion between algebra and programming.

In algebra, you can have a statement like this:

x = 2 + 3

This is a "truth-statement" that the variable `x` is equal to 2+3 or 5.

Similarly, in programming, you can write `int x = 2 + 3` and the variable `x` will end up as the integer 5. However, there's a big difference between the two statements, as will now be seen.

What if you faced the following two statement together?
x = 2 + 3
x = 11

In algebra, you would immediately recognize that this is impossible. `x` cannot be both `2+3` and `11` since they're not equal. However, in programming, `=` is not a statement of truth, it's an action that assigns a value to a variable.
So you can assign `2+3` to `x` and then afterwards assign `11` to `x`, and `x` will now be set to `11` instead of 5.

Equality Check
If you wanted to check if something was equal in programming, you use `==`. For example:

``````int x = 2 + 3; //assignment
x == 11; //this would be false
``````

Review this:

• `=` assignment
• `==` equality check

### Challenge

After the following code runs, what number will `sum` equal?

``````int x = 2;
int y = 5;
x = 100;
int sum = x+y;
``````

Alternatively, you can try out Learneroo before signing up.

• #### Matthew

Easy I'm liking this website.

• #### Jamison Norwood

I love this site. Now every other book is looking like a reference sheet.

• #### Brent Jones

You say "In the following code, what number will sum equal?"
It would be better to say "In the following code, what number will sum become?"
Also, you should give an extra example of multi-line assignment of variables before testing student understanding

• #### heya

This is amazing thank you so much

• #### Kenneth Au

Thanks to this website, I dont feel like a dumb as.. anymore!

• #### xiaochayou

so good, I like it so much!

• Good site so far :)

• #### Derpybunneh

It's easy. Forget the int x = 2 and go to x = 100 and add the y to the x.

• #### Paul Lee

I have increased my programming knowledge by 500% in the last 10 minutes.

• #### Gomati Damle

In the code why it is written
int x = 2;
int y = 5;
x = 100; .Can anyone tell me why data type int is not written befor x=100;

• #### Learneroo

As mentioned on the previous page, you need to declare a variable's type the first time, but afterwards you can use it without re-mentioning what type it is.

• #### thales

Yes, but i want to learn programming. And isnt this a bit to easy to really learn programming?

• #### Learneroo

You can start off easy. There's lot's of challenging material later if you want it!

• #### thales

ok i want that challenging stuff :-)

• #### Learneroo

When you're ready, check out Algorithms

• #### thales

we will, but we are not ready yet :-)

• #### Heckingson Jumbo

this is just like js and c

• #### Dion Matthew Levy

This was my hardest challenge yet...How does 100 + 5 = 105 if x=2???? Computers are DU|\/|@\$\$3\$ !!!! If X(2)=100 And X(1)=2 and Y(5) then wouldn't x+x+y =107? the only place xxy ever made sense was in Klinefelter syndrome! :p

Thanks.

• #### chima oscar

Got confused here since x = 100; wasn't given any data type.

Great Website! Thanks.

• #### paul. kirsch

This website makes a lot of sense, because a lot of people are not employed or partially employed and can't afford the high monthly costs of other training programs. Also, the questions are simple

• #### COD

Am so great-full for the amazing challenges on this website