Small Grey Outline Pointer '분류 전체보기' 카테고리의 글 목록 (26 Page)
본문 바로가기

분류 전체보기264

2차원 배열 /for문 복습(이중for문) 2차원 배열 배열 안에 배열 2차원 배열 선언 자료형 배열명[행][열] = {{값1, 값2}, {값3, 값4}, {값5, 값6}, ...}; 자료형 배열명[행][열]= [초기값, }; 2차원 배열 사용 int arrData[2][3]={0, } *(배열명 + 9) +2 //주소값 *(*(배열명 +2)) // 값 (두번 접근했으므로 주소값이 아닌, 값!) *(*(배열명)+2) = // 0행 3열 이중 for문(Nested For) A: for (초기식; 조건식; 증감식){ 실행할 문장; B: for(초기식; 조건식;증감식){ 실행할 문장; } 실행할 문장; } A 반복문은 안에 작성 된 문장이 모두 끝나야 다음 반복으로 넘어가기 때문에 B 반복문은 A 반복 횟수만큼 초기식으로 돌아간다 실행할 문장 1 : .. 2022. 3. 12.
포인터와 배열 응용문제 풀기 #include void main() { //입력 받은 숫자들을 거꾸로 출력 int n; int arr[1000]; printf("입력할 숫자의 개수: "); scanf_s("%d", &n); for (int i = 0; i = 0; i--) { //arr[n]=맨 마지막 숫자, i=n-1=마지막에 해당하는 숫자 printf("%d ", arr[i]); } } #include void main() { //짝수의 개수 구하기 int n; int arr[100]; scanf_s("%d", &n); for (int i = 0; i < n; i++) { scanf_s("%d", &arr[i]); } in.. 2022. 3. 6.
포인터와 배열 연습문제 풀기, null문자 포인터와 배열 연습문제 #include void main() { //1~100 까지 배열에 담은 후 홀수만 출력 int arData[100] = { 0, }; for (int i = 0; i < 100; i++) { arData[i] = i + 1; if (arData[i] % 2 == 1) { printf("%d\n", arData[i]); } } //1~100까지 배열에 담은 후 짝수의 합 출력 int arData[100] = { 0, }; int total = 0; for (int i = 0; i < 100; i++) { arData[i] = i + 1; if (arData[i] % 2 == 0) { total += arData[i]; } } printf("%d\n", total); //A~F까지 .. 2022. 3. 6.
포인터와 배열 #include void main() { int a = 20; int *ptr_a; //포인터 한개를 선언 ptr_a = &a; printf("a의 값: %d\n", a); printf("a의 주솟값: %d\n", &a); printf("ptr_a 에 저장된 값: %d\n", ptr_a); printf("ptr_a가 가르키는 변수의 값: %d\n", *ptr_a); //*ptr_a = a int a = 10; int b = 20; int* ptr; ptr = &a; printf("ptr이 가리키는 변수에 저장된 값: %d\n", *ptr); ptr = &b; printf("ptr이 가리키는 변수에 저장된 값: %d\n", *ptr); int a = 10; int* ptr; ptr = &a; int** p.. 2022. 3. 6.
반복문 연습문제 풀기 #include void main() { int i; i = 1; while (i 2022. 3. 6.
연산자 조건문 반복문 문제풀기 #include void main() { //입력받은 n줄 까지 홀수 개의 숫자만 출력 되도록 반복하기 //1 //1 2 3 //1 2 3 4 5 //1 2 3 4 5 6 7 // i 번째 줄에서 출력되는 숫자의 개수는 2*i-1 int n; printf("정수를 입력하세요: "); scanf_s("%d",&n); for (int i = 1; i 2022. 3. 5.
반복문 연습/for문/break #include void main() { int i; i = 1; while (i 2022. 3. 5.
문자열 공부 scanf, string #include void main() { //apple /*char fruit[6] = { 'a', 'p', 'p', 'l', 'e' };*/ char fruit[6] = "apple"; printf("%s", fruit); } #include void main() { //""; : 빈 문자열 char fruit[6] = ""; printf("과일이름: "); scanf_s("%s", &fruit, sizeof(fruit)); printf("%s 는 맛있어!!", fruit); } #include void main() { const char* fruit = "apple"; //const 직접 접근해서 주소를 바꾸지 말라는 의미 fruit = "banana"; printf("%s", fruit); //*f.. 2022. 3. 4.
반복문/while문 #include void main() { char* msg = "Q. 다음 중 동물이 아닌 것은?"; char* choiceMsg = "1.강아지\n2.고양이\n3.코뿔소\n4.어묵"; char* resultMsg = ""; int choice = 0; int answer = 4; while (1) { printf("%s\n%s\n", msg, choiceMsg); scanf_s("%d", &choice); if (choice == answer) { resultMsg = "정답!"; } else if (choice >= 1 && choice 2022. 3. 3.
if문 복습 조건문 조건문1. if문 항상 결과값이 참 혹은 거짓으로 나오는 식 비교연산자, 3 2022. 2. 28.