When you assign a new value to a variable that already exists, it replaces the previous value.
int myNum = 15; // myNum is 15 myNum = 10; // Now myNum is 10 |
You can also assign one variable’s value to another:
int myNum = 15;
int myOtherNum = 23; // Assign the value of myOtherNum (23) to myNum // myNum is now 23, instead of 15 |
Alternatively, you can duplicate values into empty variables:
// Create a variable and assign the value 15 to it int myNum = 15; // Declare a variable without assigning it a value // Assign the value of myNum to myOtherNum // myOtherNum now has 15 as a value |
To combine variables, you can utilize the + operator.
int x = 5; int y = 6; int sum = x + y; printf(“%d”, sum); |