Curriculum
Course: C basic
Login

Curriculum

C basic

C Introduction

0/1

C Get Started

0/1

C Comments

0/1

C Constants

0/1

C Operators

0/1

C Break and Continue

0/1

C User Input

0/1

C Memory Address

0/1

C Structures

0/1
Text lesson

Change Values

Change Variable Values

When you assign a new value to a variable that already exists, it replaces the previous value.

Example

int myNum = 15;  // myNum is 15
myNum = 10// Now myNum is 10 

You can also assign one variable’s value to another:

Example

int myNum = 15;

int myOtherNum = 23;

// Assign the value of myOtherNum (23) to myNum
myNum = myOtherNum;

// myNum is now 23, instead of 15
printf(“%d”, myNum); 

Alternatively, you can duplicate values into empty variables:

Example

// Create a variable and assign the value 15 to it
int myNum = 15;

// Declare a variable without assigning it a value
int myOtherNum;

// Assign the value of myNum to myOtherNum
myOtherNum = myNum;

// myOtherNum now has 15 as a value
printf(“%d”, myOtherNum); 

Add Variables Together

To combine variables, you can utilize the + operator.

Example

int x = 5;
int y = 6;
int sum = x + y;
printf(“%d”, sum);