Desc :

 

쉼표 연산자는 비슷한 의미의 코드를 이어 붙이는데 사용된다.

 

변수를 여러번 이어 붙여 한번에 변수를 선언하고 초기화

(가독성 문제로 지양하는 방식이긴 함)

 

 


Source Code :

#include <iostream>

using namespace std;

int main()
{
	int apple = 1000, banana = 2000, carrot = 500;

	printf("과일 채소 가격\n");
	printf("사과 :  %d원 , 바나나 : %d원, 당근 : %d원 \n", apple, banana, carrot);

	return 0;
}

 


Result :

'C++' 카테고리의 다른 글

[C++] 029 캐스트 연산자  (0) 2021.03.18
[C++] 028 비트 연산자  (0) 2021.03.18
[C++] 026 조건부 삼항 연산자  (0) 2021.03.18
[C++] 020 논리형 변수  (0) 2021.01.24
[C++] 019 실수형 변수  (0) 2021.01.24

+ Recent posts