Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 시작해요 언리얼 2022
- Programming
- 백준
- guide
- parameter
- String
- Unreal Engine 5
- w3school
- dfs
- github
- C#
- W3Schools
- Class
- dynamic
- Material
- 파이썬
- Basic
- UE5
- loop
- Algorithm
- Tutorial
- python
- DP
- 문제풀이
- Unity
- c++
- 오류
- 기초
- 프로그래밍
- 재귀
Archives
- Today
- Total
행복한 개구리
C++ Tutorial - Conditions / Short Hand If Else 본문

If... Else 짧게 작성하기 (3중 연산자)
if else를 짧게 쓸 수 있는 것이 있는데 3개의 연산되는 함수로 이루어져 있어 3중 연산자로 알려진 것입니다. 이것은 여러 줄의 코드를 단 한줄로 대체할 수 있습니다. 또한 if else 선언문을 간단하게 대체할 때 사용됩니다.
문법
variable = (condition) ? expressionTrue : expressionFalse;
if... else 사용:
예시
#include <iostream>
using namespace std;
int main() {
int time = 20;
if (time < 18) {
cout << "Good day.";
}
else {
cout << "Good evening.";
}
}

당신은 이것을 간단하게 작성할 수 있습니다.
예시
#include <iostream>
using namespace std;
int main() {
int time = 20;
string result = (time < 18) ? "Good day." : "Good evening.";
cout << result;
}

'C++ > 공부내용' 카테고리의 다른 글
| C++ Tutorial - While Loop / While Loop (0) | 2022.06.16 |
|---|---|
| C++ Tutorial - Switch (0) | 2022.06.16 |
| C++ Tutorial - Conditions / Else (0) | 2022.06.14 |
| C++ Tutorial - Conditions / If (0) | 2022.06.14 |
| C++ Tutorial - Booleans / Boolean Expressions (0) | 2022.06.14 |