What are operators and variables?
In C, you are essentially working with variables and how you work with them is the operator.
Once you learn the terminology the more easier it is to follow.
There are numerous of operators. When working with math, the typical operators are all available. There is +, -, / (divide), * (multiply). If you see ++, that means plus 1, -- means minus one. If you see myInt++, that means myInt plus one. Example myInt = 3, therefore myInt++ = 4.
Now to get variables to work you must first declare it. Why do you need to declare it? Well, it is essential to tell the computer here is my data, and I will be working with this data.
For example, int myInt, that tells the computer you will be working with an interger named myInt. You do this at the beginning of your function. You can declare multiple variables at once, you just need to separate them by a comma. For example: int myInt, myNumber.
For example:
#include stido.h (the rules or sets of premade functions)
int main (always the beginning of our program)
{int myInt; ( declaring the data, myInt will be an integer)
myInt = 3; (stating that myInt equals number 3)
return 0;} (telling the computer the program is finished)
Not every exciting example, but it shows that by telling the computer that I will be working with myInt, it will know what to expect in the following code. Sometimes the computer will even tell you that you have declared something but didn't use it. That can point to an error where you mistyped a name of your variable or capitalized the wrong letter.
Simple isn't it. Actually it took a bit for my poor brain the wrap around it. There are lots of example in the books and the internet that I've read, and this is how I come to understand it. You can correct me if I'm wrong or have any better examples that you come up with.
Next up: Loops!!!!!

No comments:
Post a Comment