9차시 - jeongpaljack/Cstudy GitHub Wiki

문자

  • 컴퓨터 상에 존재하는 모든 정보(음성, 동영상 등)들은 정수로 저장이 된다
  • 정수를 7비트 형태의 문자로 변환하는 과정을 encode라고 부름

문자열 출력

  • Hello를 저장하면 H E L L O \0 총 6바이트 크기의 배열로 저장됨
  • s에 Hello를 넣고 %s, s를 하면 s에서 \0이 나올 때까지 문자열을 출력함
#include <stdio.h>

int main() {
	char* s = "ABC";
	char arr[4] = "ABC";
	printf("%s, %s\n", s, &arr[0]);
}

%s

  • 문자열 출력 함수
  • 문자열의 첫 번째 주소값을 넣어줘야 작동
  • \0, 즉 NULL 값이 나올 때까지 문자 출력을 반복한다

정적 데이터 영역

  • "ABC"와 같은 문자열 리터럴은 정적 데이터 영역에 저장된다.
  • 정적 데이터 영역은 프로그램이 실행될 때 메모리에 할당된다.

당일 작성한 코드

#include <stdio.h>

void PrintStringToAscii(const char* s1) {
	for (int i = 0; s1[i] != '\0'; i++)
		printf("%c : %d\n", s1[i], s1[i]);
	printf("\n");

}

int main() {

	PrintStringToAscii("HELLO");
	PrintStringToAscii("HEEE");
	PrintStringToAscii("HE");
	PrintStringToAscii("HELL");
	PrintStringToAscii("HELO");
	PrintStringToAscii("LLO");
	PrintStringToAscii("ELLO");
	PrintStringToAscii("LO");
}



//#include <stdio.h>
//
//int main() {
//	char* s1 = "ABCDEF";
//
//	for (int i = 0; s1[i] != '\0'; i++)
//		printf("%c : %d\n", s1[i], s1[i]);
//}




//#include <stdio.h>
//
//int main() {
//	char* s = "ABC";
//	printf("%c, %c\n", s[0], "ABC"[0]);
//	printf("%s, %s\n", s+1, "ABC"+1);
//	printf("%p, %p\n", s, "ABC");
//}
//


//#include <stdio.h>
//
//int main() {
//	char* s = "ABC";
//	char arr[4] = "ABC";
//	printf("%p, %p\n", s, &arr[0]);
//	printf("%s, %s\n", s, &arr[0]);
//}



//#include <stdio.h>
//
//int main() {
//	int n1 = 65;
//	int n2 = 'A';
//	printf("%c %d\n", n1, n2);
//	printf("%c %d\n", n1, n2);
//
//}


//#include <stdio.h>
//
//int main() {
//	int n = 65;
//	printf("%c %d\n", n, n);
//	printf("%c %d\n", 65, n);
//	printf("%c %d\n", 'A', 'A');
//}



//#include <stdio.h>
//
//int main() {
//	double da[4] = { 1.1, 2.2, 3.3, 4.4 };
//	double* pd = &da[1];
//	printf("%g %g\n", da[0], pd[-1]);
//
//}



//#include <stdio.h>
//
//int main() {
//	int arr[2] = { 100, 200 };
//	int* p = &arr[0];
//
//	printf("%d %d\n", arr[0], arr[1]);
//	printf("%d %d\n", p[0], p[1]);
//
//}


//#include <stdio.h>
//
//int main() {
//	int arr[4] = { 100, 200, 300, 400 };
//	int* p = &arr[0];
//
//	printf("%p %p\n%d %d\n", &arr[0], p, arr[1], *(p+1));
//	printf("%p %p\n%d %d\n", &arr[1] + 1, p + 1, arr[1], *(p + 2));
//	printf("%p %p\n%d %d\n", &arr[1] + 2, p + 2, arr[3], p[1]);
//}



//#include <stdio.h>
//
//int main() {
//	int n = 10;
//	int* p = &n;
//
//	printf("%p %p\n%d %d\n", &n, p, n, *p);
//	printf("%p %p\n%d %d\n", &n + 1, p + 1, n++, *p + 1);
//	printf("%p %p\n%d %d\n",  &n + 2, p + 2, n, *p);
//}


//#include <stdio.h>
//
//int main() {
//	int n = 10;
//	int* p = &n;
//
//	printf("%p %p\n%d %d\n", &n, p, n, *p);
//	printf("%p %p\n%d %d\n", &n+1, p+1, n++, *p + 1);
//	printf("%p %p\n%d %d\n", &n+2, p+2, n, *p);
//}



//#include <stdio.h>
//
//int main() {
//	char arr[3] = { 10, 20, 30 };
//	double darr[4] = { 10.1, 20.2, 30.3, 40.4 };
//	char* pc = &arr[0];
//	double* pd = &darr[0];
//	printf("%g", *(pd + 1));
//}


//#include <stdio.h>
//
//int main() {
//	int n = 10;
//	int n2 = n;
//	int* p = &n;
//	int* p2 = p;
//}


//#include <stdio.h>
//
//void PrintStringToAscii(const char* s) {
//	for (int i = 0; s[i] != '\0'; ++i) {
//		printf("%c : %d\n", s[i], s[i]);
//	}
//}
//
//int main() {
//	printf("%s\n", "Hello");
//	PrintStringToAscii("Hello!");
//}
⚠️ **GitHub.com Fallback** ⚠️