4차시 - jeongpaljack/Cstudy GitHub Wiki

CPU와 RAM의 소통

  • address bus, data bus, control bus가 존재

  • 128비트로 높아져도 성능이 별로 차이가 없어 64비트로 고정됨

  • address bus는 주소 관련 데이터 통로

cpu가 ram에게 주소값 요청

  • data bus는 데이터를 주고받는 통로

양방향으로 데이터를 주고받음

  • control bus는 1비트

데이터를 write할지 read할지 두가지만 결정

확인

#include <stdio.h>

int main(void) {
	int n = 10;

	printf("%p, %d\n", &n, n);
	printf("%p, %d\n", &n + 1, n + 1);
}

결괏값은 주소값이 4가 증가, 즉 int(4바이트)만큼 증가

conio.h

  • _getch()는 엔터를 건너뛰고 한 자리의 숫자를 입력받음
int main(void) {


	switch ( _getch() - '0' ) {
	case 1:
		printf("안\n"); break;
	case 2:
		printf("녕\n"); break;
	case 3:
		printf("하\n"); break;
	case 4:
		printf("세\n"); break;
	case 5:
		printf("요\n"); break;

	default:
		printf("다시 입력\n");
		break;
	}
}

다음과 같은 코드 실행 시, 숫자를 입력하자마자 바로 출력

for문 - i++과 ++i

#include <stdio.h>

int main(void) {
	printf("hello\n");
	for (int i = 1; i < 10; i++) {
		printf("hello\n");
	}
	return 0;
}
#include <stdio.h>

int main(void) {
	printf("hello\n");
	for (int i = 1; i < 10; ++i) {
		printf("hello\n");
	}
	return 0;
}

두 코드는 차이가 없다.

i++ / ++i는 for문 안의 코드가 전부 실행된 후 실행되기 떄문

문자 입력 후 바로 출력

#include <stdio.h>
#include <conio.h>
int main(void) {
	while(true) {
		char c = _getch();
		if (c == 'q')
			break;
		printf("%c", c);
	}
	return 0;
}

문자를 입력받고 바로 그 문자를 출력하는 코드이다.

⚠️ **GitHub.com Fallback** ⚠️