본문 바로가기
C/c언어 수업

p255 goto

by sj0020 2020. 8. 5.
#include <stdio.h>

int main(void)
{
	int num;
	printf("enter num: ");
	scanf("%d", &num);

	if (num < 0)
		goto AAA;
	else if (num == 0)
		goto BBB;
	else
		goto CCC;

	AAA:
		printf("negative num\n");
		goto END;
	BBB:
		printf("zero\n");
		goto END;
	CCC:
		printf("positive num\n");
		goto END;
	END:
		printf("turn off program\n");

	return 0;
}

goto 잘 안씀 -> 스파게티. 에러났을 때 어디서 났는지 찾기 어려움

모듈화해서 쓰는게 나음

'C > c언어 수업' 카테고리의 다른 글

p271 while 구구단  (0) 2020.08.05
p269 while  (0) 2020.08.05
p245 switch  (0) 2020.08.05
p242 삼항연산자 int - positive/negative/absolute value  (0) 2020.08.05
p.223 scanf 입력받을때 , / - | 이용해 데이터 구분  (0) 2020.08.05