What is the C language variable?
This article is to share with you about what the C language variable is. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Introduction of C language variables
The variable is equivalent to the representation of a data storage space in memory, you can think of the variable as the house number of a room, we can find the room through the house number, and the variable (value) can be accessed through the variable name.
Basic steps for using variables
1) declare variables
Int num
2) assignment
Num = 60
3) use
Printf ("num=%d", num)
4) it can also be achieved in one step: int num2 = 99
Case study of getting started with variable
Look at the demo and explain the code
/ / 1. Declare a variable [tell the computer to open a room]
Int num = 1; / / Integer
Double score = 2.3; / / decimal
Char gender = 'Aids; / / character
Char name [] = "Qingyu"; / / string
# include void main () {int num = 1; double score = 123; char sex='N'; char name [] = "Qingyu" / / output / * if output is integer% d if output is decimal% f, keep two decimal places% .2f if output is character% c if output is string% s * / output different data with% s * / / The corresponding format should correspond to printf ("num=%d,score=%.2f,sex=%c,name=%s", num,score,sex,name). Notes on the use of getchar ();} variables
1) the variable represents a storage area in memory (different data types take up different amounts of space)
2) the area has its own name and type
3) variables must be declared before using
4) the data in this area can be constantly changed within the same type.
5) variables cannot have the same name in the same scope
6) three elements of variables (variable name + value + data type), please pay attention to this.
Thank you for reading! This is the end of this article on "what are C language variables?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!