0
I can't understand declaring variables
4 odpowiedzi
+ 8
int i,j; <<<this is a declaration. You declare 2 variables to a data type "int" without giving them a value.
i = 20; <<<this is initialization you initialize "i" variable to a value "20".
j=i; <<<this is an assignment you assign variable j to the value of i.
variable "j" and "i" now have a value of 20.
//output of both variables would be 40
hope that helps
+ 3
Hello Shehab,
When you type: int x = 3; you are pretty much telling the computer the following:
- I want to save some information in the computer memory.
- The information I want to save is an integer (whole number)
- I want to name this integer 'x' so every time I need it I can call its name
- I want the initial value of x to be 3. Note that you can change the value of x any time, that's why we call it a variable (means it changes).
Hope this helps! HAPPY CODING!
+ 2
a variable is a reference to a value like "he"
instead of saying:
I like Bob. I think Bob is cool. Bob likes blue
we say:
I like Bob. I think he is cool. he likes blue
so we declare a variable once and then refer to it as many times as we need.
in c++ we simply state the type of variable and the name
for example:
string newFriend;
if we want we can also set a value
like so:
string newFriend = "Bob";
or we could set it after as well
like so:
string newFriend;
newFriend = "Bob";