Just like in algebra, one of the first thing you must know in programming is how variables work. I am sure you understand, but if you don't, a variable is a letter or symbol that can represent any number. In C++, they can also represent things such as words or characters, but we will get into those later.
Lets run through the most basic types of variables:
int x;
X is now an integer so it can be negative or positive, but NOT a decimal.
double x;
X can now be negative, positive, AND a decimal.
char x;
X can now be any one character like Y or H.
char's are NOT values, so you CANNOT do any sort of mathematical operation with them, like this:
char x = 10;
char y = 5;
x + y = z;
z = 15;
WRONG!!!
but you CAN do this:
char y;
char x = 'h';
y = x;
Now y = "h" because x = "h" and we said y = x;
But now we need to understand how to assign values or characters to these variable types!
For int:
int x;
x = 5;
OR
int x = 5;
For double:
double x;
x = 1.5;
OR
double x = 1.5;
For char:
char x;
x = 'h';
OR
char x = 'h';
Thanks for reading and please try to refer this blog to others via the internet or whatever!
Comments
Post a Comment