일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- 리액트프로젝트
- msa개념
- 웹개발자
- BCIT
- 코드잇
- jvm메모리구조
- CSS
- MSA
- MVC
- 안드로이드
- microservices
- Bambino
- 데이터베이스
- 웹개발
- DB
- jsp
- 밤비노
- servlet
- mysql
- Programming
- 웹개발기초
- job
- two pointers
- sql
- 자바
- html
- Java
- C
- SpringFramework
- coding test
- Today
- Total
초보 개발자의 기록
[C] Variables 본문
Variables
Variables are containers for storing data vaules.
int: Stores integers without decimals
float: Stores floating point numbers with decimals
char: Stores single characters. Char values are surrounded by single quotes
Declaring (Creating) Variables
To create a variable,specify the type and assign it a value
type variableName = value;
The equal sign is used to assign a value to the variable.
You can also declare a variable without assigning the value, and assign the value later.
Format Specifiers
Format specifiers are used together with the printf() function to tell the compiler what type of data the variable is storing.
It is basically a placeholder for the variable value.
A format specifier starts with a percentage sign %, followed by a character.
int %d
char %c
float %f
To combine both text and a variable, separate them with a comma inside the print() function
Change Variable Values
If you assign a new value to an existing variable, it will overwrite the previous value
You can also assign the value of one variable to another or copy values to empty variables
Add Variables together
To add a variable to another variable, use the + operator
int x = 1;
int y = 2;
int sum = x + y;
Declare Multiple Variables
To declare more than one variable of the same type, use a comma-separated list
int x = 1, y = 2, z = 3;
Variable Names
All C varialbes must be identified with unique names which are called identifiers.
Identifiers can be short names or more descriptive names
It is recommended to use descriptive names in orfer to create understanable and maintainable code
General rules for maing variables
- Names can contain letters, digits and underscores
- Names must begin with a letter or an underscore(_)
- Names are case sentivie
- Names cannot contain whitespaces or special characters
- Reserved words (such as int) cannot be used as names