Development/C, C++(556)
-
Ex-구조체에서 typedef 사용 방법 두가지
구조체에서 typedef 사용 방법 두가지 구조체 정의와 동시에 typedef 선언 구조체 정의와 개별적으로 typedef 선언 소스코드 #include // 구조체에서 typedef를 사용하는 방법 1 typedef struct score{ double math; double english; double korean; double total; double average; } SCORE; // 구조체 변수가 아니라, SCORE는 struct score라는 데이터 타입을 의미 struct student{ int no; SCORE score; // struct score s; }; // 구조체에서 typedef를 사용하는 방법 2 typedef struct student STUDENT; //STUDENT는s..
-
함수 형태 1 2 3 4 - 출력과 입력형태에 따른 분류
함수 형태 - 출력과 입력형태에 따른 분류http://codedragon.tistory.com/5249 함수의 형태 1 - 출력형태O 입력형태O //함수 정의 형태 - OO int plus(int x, int y) {//함수의 시작 int result; result = x + y; return result; //반환값 }//함수의 종료 함수의 형태 2 - 출력형태O 입력형태X //함수 정의 형태 - OX int input(void) {//함수의 시작 int in; scanf("%d", &in); return in; //반환값 }//함수의 종료 함수의 형태 3 - 출력형태X 입력형태O //함수 정의 형태 - XO void input(int x) {//함수의 시작 int i=x; printf("%d", i)..
-
함수 형태 - 출력과 입력형태에 따른 분류
함수 형태 - 출력과 입력형태에 따른 분류 구분 동일의미 입력값 · 입력형태 · 함수의 인수 · 입력 인수 · 함수의 입력변수 · 매개변수 · 파라미터(Parameter) 출력값 · 출력형태 · 반환값 · 돌려주는 값 · 리턴값 함수 · 메소드 · 프로시져(Procedure)
-
Error-입력버퍼 비우는 방법
입력버퍼가 비워지지 않은 경우(비정상 출력) 입력버퍼가 비워진 경우(정상 출력) 증상입력버퍼에 데이터가 남아 있기 때문입니다.scanf("%d", &a); 이전 구문에서 입력이 끝나면 입력버퍼에 \n(new line, 개형)이 남아 있습니다. 그래서 scanf("%c",&ch)구문의 ch에 기존에 있던 \n이 입력값으로 들어가고 다음 구문이 실행되어져 버렸습니다. 표준 입력시 사용자로부터 입력받는 즉시 처리되는 것이 아니라입력버퍼를 거친 후(임시저장) 프로그램에서 입력버퍼에 있는 데이터를 가져가 사용하게 됩니다.그래서 위와 같은 증상이 발생할 수 있으며 이를 해결하기 위해서는 입력버퍼를 비워주어야 합니다. 입력버퍼를 비우는 방법· fflush(stdin);· scanf("%*c");· scanf(" %*..
-
Ex-중첩구조체 초기화
중첩 구조체를 선언하고 동시에 초기화하기 중첩 구조체 초기화 방법 2가지 확인 소스코드 #include struct score{ double math; double english; double korean; double total; }; struct student{ int no; struct score ss; // 구조체 변수 ss를 구조체 student의 멤버 변수로 사용(중첩 구조체) }; int main(void){ // 중첩구조체 초기화 방법 1 struct student stu={1234567, {90, 80, 60, 0}}; // 중첩구조체 초기화 방법 2 - {}(중괄호) 생략 가능 // struct student stu={1234567, 90, 80, 60, 0}; stu.ss.total=..
-
Ex-멤버변수로 구조체 변수를 사용하는 중첩구조체
멤버변수로 구조체 변수를 사용하는 중첩구조체 중첩구조체는 구조체 내에 구조체가 포함되어 있는 구조 메모리 도식도 소스코드 #include struct score{ double math; double english; double korean; double total; }; struct student{ int no; struct score ss; // 구조체 변수 ss를 구조체 student의 멤버 변수로 사용(중첩 구조체) }; int main(void){ struct student stu; stu.no=1234567; stu.ss.math=90; stu.ss.english=80; stu.ss.korean=70; stu.ss.total=stu.ss.math+stu.ss.english+stu.ss.korea..