Skip to content

Instantly share code, notes, and snippets.

@SangRyul
Created May 13, 2018 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SangRyul/339f465671b287f649bd6812915ff7b9 to your computer and use it in GitHub Desktop.
Save SangRyul/339f465671b287f649bd6812915ff7b9 to your computer and use it in GitHub Desktop.
/*Program 1*/
//#pragma warning(disable:4996)
//#include<stdio.h>
//
//int main(void) {
//
// int arr[2][2] = { 10,20,30,40 };
//
// for (int i = 0; i < 2; i++) {
// for (int j = 0; j < 2; j++) {
// printf("%x ", &arr[i][j]);
// }
// printf("\n");
// }
//
// printf("------------------------------- \n");
//
// printf("%x %x \n", arr[0], &arr[0][0]);
// printf("%x %x \n", arr[1], &arr[1][0]);
//
//
// system("pause");
//
// return 0;
//}
/*Program 2*/
//#pragma warning(disable:4996)
//#include<stdio.h>
//
//int main(void) {
//
//
// int arr[2][2] = { 10,20,30,40 };
//
// printf("%x %x \n", &arr[0][0], &arr[0][1]);
// printf("%x %x \n", &arr[1][0], &arr[1][1]);
//
// printf("------------------------ \n");
//
// printf("%x %x \n", arr[0] + 0 , arr[0] + 1);
// printf("%x %x \n", arr[1] + 0, arr[1] + 1);
//
// printf("------------------------ \n");
//
// printf("%x %x \n", *(arr + 0) + 0 , *(arr + 0) + 1);
// printf("%x %x \n", *(arr + 1) + 0, *(arr + 1) + 1);
//
// printf("------------------------ \n");
//
//
// system("pause");
// return 0;
//}
/*Program 3*/
//#pragma warning(disable:4996)
//#include<stdio.h>
//
//int main(void) {
//
// //괄호를 일부러 붙이는 이유는 우선연산 순위 때문입니다.
//
// int arr[2][2] = { 10,20,30,40 };
//
// printf("%x %x \n", *&arr[0][0], *&arr[0][1]);
// printf("%x %x \n", *&arr[1][0], *&arr[1][1]);
//
// printf("------------------------ \n");
//
// printf("%x %x \n", *(arr[0] + 0) , *(arr[0] + 1));
// printf("%x %x \n", *(arr[1] + 0), *(arr[1] + 1));
//
// printf("------------------------ \n");
//
// printf("%x %x \n", *(*(arr + 0) + 0) , *(*(arr + 0) + 1));
// printf("%x %x \n", *(*(arr + 1) + 0), *(*(arr + 1) + 1));
//
// printf("------------------------ \n");
//
// system("pause");
//
// return 0;
//}
/*Program 4 더블 포인터*/
//#pragma warning(disable:4996)
//#include<stdio.h>
//
//int main(void) {
//
// char c1 = 'A';
// char * cp = NULL;
// char ** cpp = NULL;
//
// cp = &c1;
// cpp = &cp;
//
// printf("%c %x %x \n", c1, cp, cpp);
// printf("%x %x %x \n", &c1, &cp, &cpp);
// printf("%c %c %c \n", c1, *cp, **cpp);
//
// system("pause");
// return 0;
//}
/*문자열*/
/*Program 5 배열 포인터*/
//#pragma warning(disable:4996)
//#include<stdio.h>
//
//int main(void) {
//
// int arr[2][3] = {
// 10,20,30,
// 40,50,60
// };
//
// int(*p)[3] = NULL; // p에 3열을 가지는 2차원 배열 arr의 시작 주소를 저장
// //
//
// p = arr; //자료형이 안 맞으면 어떻게 될까
//
// printf("%d %d %d \n", p[0][0], p[0][1], p[0][2]);
// printf("%d %d %d \n", p[1][0], p[1][1], p[1][2]);
//
// printf("-------------------------------------- \n");
//
//
// system("pause");
// return 0;
//
//}
/*Program 6 배열 포인터 자세히*/
//#pragma warning(disable:4996)
//#include<stdio.h>
//
//int main(void) {
//
// int arr[2][3] = { 10,20,30,40,50,60 };
// int(*p)[3] = NULL;
//
// p = arr; // p = &arr[0][0];
//
// printf("--------#1-----------\n");
// printf("%x %x %x \n", &p[0][0], &p[0][1], &p[0][2]);
// printf("%x %x %x \n", &p[1][0], &p[1][1], &p[1][2]);
//
// printf("--------#2-----------\n");
// printf("%x %x \n", p[0], p[1]);
// printf("%x %x \n", *(p + 0), *(p + 1));
//
// printf("--------#3-----------\n");
// printf("%d %d %d\n", *(p[0]+0), *(p[0]+1), *(p[0]+2));
// printf("%d %d %d\n", *(p[1] + 0), *(p[1] + 1), *(p[1]+2));
//
// printf("--------#4-----------\n");
// printf("%d %d %d\n", *(*(p+0)+0), *(*(p + 0) + 1), *(*(p + 0) + 2));
// printf("%d %d %d\n", *(*(p + 1) + 0), *(*(p + 1) + 1), *(*(p + 1) + 2));
//
//
// system("pause");
// return 0;
//}
/*포인터 배열*/
//보통 배열과 달리 포인터 배열에서는 배열안에 값대신 주소값을 저장합니다.
//#include<stdio.h>
//int main(void) {
//
// int a = 1, b = 2, c = 3;
// int * ptr[3];
//
// ptr[0] = &a;
// ptr[1] = &b;
// ptr[2] = &c;
//
// for (int i = 0; i < 3; i++) {
// printf("%x %d \n", *ptr[i], ptr[i]);
// }
//
//
// system("pause");
// return 0;
//}
/*포인터 배열 자세히*/
//#include<stdio.h>
//
//int main(void) {
//
// int a = 10, b = 20, c = 30;
// int *ap[3];
//
// ap[0] = &a;
// ap[1] = &b;
// ap[2] = &c;
//
// printf("%x %x %x \n", &a, &b, &c);
// printf("%x %x %x \n", ap[0], ap[1], ap[2]);
// printf("%x %x %x \n", *(ap+0), *(ap+1), *(ap+2));
// printf("---------------------------\n");
//
//
// printf("%d %d %d \n", &a, &b, &c);
// printf("%d %d %d \n", *ap[0], *ap[1], *ap[2]);
// printf("%d %d %d \n", **(ap + 0), **(ap + 1), **(ap + 2));
// printf("---------------------------\n");
//
// system("pause");
// return 0;
//}
/*함수에서 포인터 사용*/
//#include<stdio.h>
//
//void func(int(*p)[3], int num1, int num2);
//
//int main(void) {
//
// int arr[2][3] = { 10,20,30,40,50,60 };
// func(arr, sizeof(arr) / 12, sizeof(arr) / 8);
//
//
// system("pause");
// return 0;
//}
//
//void func(int(*p)[3], int num1, int num2) {
//
//
//
// for (int i = 0; i < num1; i++) {
// for (int j = 0; j < num2; j++) {
// printf("%d ", p[i][j]);
// }
// printf("\n");
// }
//
//
//}
/*함수에서 포인터 사용2*/
//
//#include<stdio.h>
//
//void func(int *p);
//
//int main(void) {
//
// int arr[2][3] = { 10,20,30,40,50,60 };
// func(arr);
//
//
// system("pause");
// return 0;
//}
//
//void func(int *p)
//{
// printf("%d %d %d %d %d %d", p[0], p[1], p[2], p[3], p[4], p[5] );
//
// //printf("%d %d %d \n", p[0][0], p[0][1], p[0][2]);
// //printf("%d %d %d \n", p[1][0], p[1][1], p[1][2]);
//}
//#include<stdio.h>
//
//int main(void) {
//
// char string[] = "hello";
//
// printf("%s\n", string);
// printf("-------------\n");
//
// for (int i = 0; i < sizeof(string) / sizeof(char); i++) {
// printf("%c", string[i]);
// }
// printf("%x", string[5]);
//
// system("pause");
// return 0;
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment