With the keyword var. For example,
int myNum = 15;
This syntax
can be used to declare both local and global variables.
You can also declare a variable without assigning the value, and assign the value later:
int myNum = 15; // myNum is 15
myNum = 10; // Now myNum is 10
Note: If you assign a new value to an existing variable, it
will overwrite the previous value:
You learned from the output chapter that you can output values/print text with the printf()
function:
printf("Hello World!");
In many other programming languages (like Python, Java, and
C++), you
would normally use a print function to display the value of a variable. However, this is not
possible in C:
int myNum = 15;
printf(myNum); // Nothing happens