null
vuild_
Nodes
Flows
Hubs
Login
MENU
Notifications
Login
⌂
c-lang-beginner
Structure
intro
•
C언어란?
•
C언어의 역사
•
개발 환경 설치
basics
•
변수 (Variables)
•
자료형 (Data Types)
•
연산자 (Operators)
io
•
printf — 출력 함수
•
scanf — 입력 함수
control-flow
•
if-else 조건문
•
switch 문
•
삼항 연산자 (Ternary Operator)
loops
•
for 반복문
•
while 반복문
•
do-while 반복문
functions
•
함수 정의와 호출
•
매개변수와 반환값
•
재귀 함수 (Recursion)
arrays
•
1차원 배열
•
2차원 배열
strings
•
문자열 기초
•
문자열 함수
project
•
프로젝트: 사칙연산 계산기
Flow Structure
자료형 (Data Types)
6 / 22
printf — 출력 함수
☆ Star
↗ Full
연산자 (Operators)
#c
#c-lang
#beginner
#basics
#operators
@devpc
|
2026-03-29 13:24:25
|
GET /api/v1/flows/4/nodes/24?fv=1&nv=2
Context:
Flow v1
→
Node v2
0
Views
0
Calls
# 연산자 (Operators) ## 산술 연산자 | 연산자 | 의미 | 예시 | 결과 | |--------|------|------|------| | `+` | 덧셈 | `3 + 2` | `5` | | `-` | 뺄셈 | `3 - 2` | `1` | | `*` | 곱셈 | `3 * 2` | `6` | | `/` | 나눗셈 | `7 / 2` | `3` (정수) | | `%` | 나머지 | `7 % 2` | `1` | ```c int a = 7, b = 2; printf("%d\n", a / b); // 3 (정수 나눗셈 — 소수점 버림) printf("%d\n", a % b); // 1 (나머지) double c = 7.0; printf("%.1f\n", c / b); // 3.5 ``` --- ## 비교 연산자 결과는 항상 `1`(참) 또는 `0`(거짓)입니다. | 연산자 | 의미 | 예시 | 결과 | |--------|------|------|------| | `==` | 같다 | `3 == 3` | `1` | | `!=` | 다르다 | `3 != 4` | `1` | | `>` | 크다 | `5 > 3` | `1` | | `<` | 작다 | `2 < 1` | `0` | | `>=` | 크거나 같다 | `3 >= 3` | `1` | | `<=` | 작거나 같다 | `2 <= 1` | `0` | ```c int x = 10; printf("%d\n", x == 10); // 1 printf("%d\n", x > 20); // 0 ``` > ⚠️ `=`(대입)과 `==`(비교)를 혼동하지 마세요! --- ## 논리 연산자 | 연산자 | 의미 | 설명 | |--------|------|------| | `&&` | AND (그리고) | 둘 다 참일 때만 참 | | `\|\|` | OR (또는) | 하나라도 참이면 참 | | `!` | NOT (부정) | 참↔거짓 반전 | ```c int age = 20; int has_id = 1; if (age >= 18 && has_id) { printf("입장 가능\n"); } if (age < 13 || age > 65) { printf("할인 대상\n"); } if (!has_id) { printf("신분증이 없습니다\n"); } ``` --- ## 대입 연산자 | 연산자 | 의미 | 동일 표현 | |--------|------|-----------| | `=` | 대입 | `a = 5` | | `+=` | 더하고 대입 | `a = a + 5` | | `-=` | 빼고 대입 | `a = a - 5` | | `*=` | 곱하고 대입 | `a = a * 5` | | `/=` | 나누고 대입 | `a = a / 5` | | `%=` | 나머지 대입 | `a = a % 5` | ```c int score = 100; score -= 20; // score = 80 score *= 2; // score = 160 printf("%d\n", score); // 160 ``` --- ## 증감 연산자 | 연산자 | 의미 | |--------|------| | `++a` | 전위 증가: 먼저 1 더하고 사용 | | `a++` | 후위 증가: 먼저 사용하고 1 더함 | | `--a` | 전위 감소 | | `a--` | 후위 감소 | ```c int a = 5; printf("%d\n", a++); // 5 출력, 이후 a = 6 printf("%d\n", a); // 6 int b = 5; printf("%d\n", ++b); // 6 출력 (먼저 증가) printf("%d\n", b); // 6 ``` --- ## 연산자 우선순위 우선순위가 높을수록 먼저 계산됩니다. | 순위 | 연산자 | |------|--------| | 1 (높음) | `()`, `[]` | | 2 | `++`, `--`, `!`, `(type)` | | 3 | `*`, `/`, `%` | | 4 | `+`, `-` | | 5 | `<`, `>`, `<=`, `>=` | | 6 | `==`, `!=` | | 7 | `&&` | | 8 | `\|\|` | | 9 (낮음) | `=`, `+=`, `-=`, ... | ```c int result = 2 + 3 * 4; // 14 (곱셈 먼저) int result2 = (2 + 3) * 4; // 20 (괄호 먼저) int x = 1 + 2 > 2 && 5 > 3; // = (1 + 2) > 2 && (5 > 3) // = 3 > 2 && true // = 1 && 1 // = 1 (참) ``` > 헷갈릴 땐 **괄호로 명시**하는 것이 가장 안전합니다. --- ## 예제: 연산자 종합 ```c #include <stdio.h> int main() { int hp = 100; int damage = 35; int shield = 10; int net_damage = damage - shield; // 실제 피해 hp -= net_damage; // -= 대입 연산자 int is_alive = hp > 0; // 비교: 1 또는 0 int critical = damage >= 30 && shield < 15; // 논리 연산자 printf("남은 HP: %d\n", hp); // 75 printf("생존 여부: %d\n", is_alive); // 1 printf("크리티컬 조건: %d\n", critical); // 1 return 0; } ``` ---
자료형 (Data Types)
printf — 출력 함수
// COMMENTS
ON THIS PAGE
No content selected.