0

I can't understand declaring variables

28th Oct 2017, 8:28 PM
Shehab Ashraf
Shehab Ashraf - avatar
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
28th Oct 2017, 8:36 PM
D_Stark
D_Stark - avatar
+ 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!
29th Oct 2017, 12:47 AM
Red Hawks
Red Hawks - avatar
+ 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";
28th Oct 2017, 8:43 PM
Adam
Adam - avatar