분류 전체보기

Computer Language/C

[C] 이중포인터

이중포인터는 뭐 어려운 개념이라기보단, 말이 길어지는 개념이다. 누구의 친구의 친구의 친구의 친구 같은 느낌.. 포인터를 또 포인터로 지정해주는 경우가 있는데, 이때는 *을 두개 붙여서 표시해준다. 두번째 포인터 아래처럼 정의해준다. int** p2 = &p; 여기서 나중에 내부 값을 불러올때, *p2 라고 하면 *p2 = 100 (첫단계 주소값) **p2 라고 하면 **p2 = 20 (두번째(위 그림의 경우 마지막)단계의 내부값) 을 지칭한다. 개념이 어렵기보단 건너는 다리가 많아서 헷갈리니, 별이 2~3개 붙어있으면 유심히 보아야한다.

Computer Language/C

[C] 문자배열과 포인터, 포인터배열과 배열포인터.

혹시 틀린 부분이 있으면 지나가지 마시고 댓글로 지적해주시면 감사드리겠습니다. :-) C언어에서는 문자열을 담는 자료형이 없으므로 두가지 방법으로 문자열을 담을 수 있다. 첫번째는 배열을 이용한것, 두번째는 문자열 주소값을 가진 포인터를 이용하는것. 이 그림과 같이 int a[3][5] 라는 2차원 배열이 있고, a의 주소는 200이라고 가정했을때, 이 배열을 가르키는 포인터는 int(*p)[5] = a 가 된다. int*p = a와는 다른데, 이 배열에서 a의 기본 단위는 20바이트가 되므로, a주소값은 200 이라면, a+1 주소값은 204가 아닌 220이 된다. 그러나 int*p = a라고 정의하면, p+1의 주소값은 220이 아닌 204가 되어버려, 1:1 대응이 안되고 다른 의미가 되어버린다...

Computer Language/C

[C]포인터변수 pointer

p는 int *p 형식으로 정의되어 있으므로, int * 형식(메모리주소값.&) 만 들어갈 수 있다. 여기에 p=70과 같이 int값을 넣어버리면 오류가 난다 포인터는 변수다. 자신의 자료형과 일치하는 변수의 주소를 저장한다. (int*p 는 int의 주소만 저장하고, str의 주소는 저장할 수 없다.) 통상적으로 int의 크기는 4byte 이므로 4byte로 가정하고, 주소값은 (편의상 10진법으로) 임의로 &a = 100, &p = 500 으로 설정한 경우, [참고로 여기서 가정한 주소값은 실제로는 저렇게 대입하면 정수와 주소값의 자료형이 다르므로 불가능함. 편의상 주소값을 10진수로 표기] a[2] = *(a+2) &a[2] = a+2 배열식 표현 포인터식 표현 int* p = int *p (별 위..

Coding 수업정리/CS50

CS50-03-psets-runoff[완료]

https://cs50.harvard.edu/x/2023/psets/3/runoff/#tabulate Runoff - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu 아... 5시간 넘게 걸렸다. 길지 않은 코드이지만 오류가 너무 많이 나서 하나씩 잡는데 너무 오래걸렸다. 1. break; 가 while만 뚫는줄 알았는데, for구문도 뚫어버린다는것(1겹만 뚫는다) 그래서 무한루프가 되어 계속 오류가 남. 2. 총 득표수의 50%를 계산할때 이미 탈락한 후보를 제외하지 않아서 부분적 오류가 계속 남아있..

Coding 수업정리/CS50

CS50-03-pset-runoff if(!vote)로 function 소환..

if(!vote)로 function 소환.. 제목처럼 function은 if 조건으로 불러도 내부 함수가 모두 실행된다는걸, 직관적으로는 이해할수가 없었으나, function이라는 친구가, 비교하려고 쳐다보기만해도 갑자기 와서 자기 할일 다하고가는 이상한 친구라고 생각하면 이해가 쉬웠다. 아래 코드에서 vote라는 function을 참인지 아닌지 보려고 부른건데 문제는 vote Function 내부에 투표지 등록하는 함수가 다 들어있어서 저렇게 비교하려고 불러도, 그친구는 일을 다 해버린다는 것이다. 이게 직관적으로 이해는 안가는데, 컴퓨터라는게, 그리고 function이라는 특성을 이해하니 이해가 간다. // Query for each rank for (int j = 0; j < candidate_co..

카테고리 없음

CS50-03-problem set-runoff(more comfortable)

https://cs50.harvard.edu/x/2023/psets/3/runoff/ Runoff - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu 지금 작성중 입니다... 3주차부터는 더욱 겸손해져서 낮은 난이도먼저 풀기로 했습니다 아래는 주어진 뼈대입니다 뼈대만 150줄이 넘네요 #include #include // Max voters and candidates #define MAX_VOTERS 100 #define MAX_CANDIDATES 9 // preferences[i][j] is jth ..

Computer Language/C

정렬 sort 참고자료 링크

https://gmlwjd9405.github.io/2018/05/08/algorithm-merge-sort.html [알고리즘] 합병 정렬(merge sort)이란 - Heee's Development Blog Step by step goes a long way. gmlwjd9405.github.io https://gmlwjd9405.github.io/2018/05/06/algorithm-selection-sort.html [알고리즘] 선택 정렬(selection sort)이란 - Heee's Development Blog Step by step goes a long way. gmlwjd9405.github.io 버블 정렬(bubble sort) [알고리즘] 버블 정렬(bubble sort)이란 - H..

Coding 수업정리/CS50

CS50-03-algorithm-snackbar(오류 확인 필요)

https://cs50.harvard.edu/x/2023/problems/3/snackbar/ 더보기 strings.h bcmp - compare byte sequences bcopy - copy byte sequence bzero - zero a byte string explicit_bzero - zero a byte string ffs - find first bit set in a word ffsl - find first bit set in a word ffsll - find first bit set in a word index - locate character in string rindex - locate character in string strcasecmp - compare two strings..

Coding 수업정리/CS50

CS50-03-Algorithm-Sections

https://cs50.harvard.edu/x/2023/sections/3/ Week 3 Algorithms - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu 좌측에 괄호 안 부분을 attribute 혹은 field 라고 부른다. + 좌측처럼 candidate를 연속으로 몇번 물어보면서 데이터를 체우게 할 수도 있음 for loop 특정 숫자에 접근하려면 점으로 해서 순서로 특정할수 있음. Recursion 재귀 예시 : Factorial 좌측과 같이 표현 가능함. 좌측보다도 (미완성임) 더 길게 ..

Coding 수업정리/CS50

CS50-02-problem set-substitution

https://cs50.harvard.edu/x/2023/psets/2/substitution/ Substitution - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu 하... 3시간째 작성중인데 하나씩 구현은 되는데 이젠 띄어쓰기를 인식을 못한다.ㅠㅠ 아래는 지금까지 작성한 코드 #include #include #include string substitution(string text, int length, string key); int main(int argc, string argv[]) { //..

Coding 수업정리/CS50

CS50-02-Problem set-Readability

https://cs50.harvard.edu/x/2023/psets/2/readability/ Readability - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu Coleman-Liau index index = 0.0588 * L - 0.296 * S - 15.8 L은 100단어당 들어간 알파벳의 숫자 S는 100단어당 들어간 문장의 숫자. 이 값을 이용하여 입력된 문장의 수준을 판별하는 프로그램 작성. 꽤나 복잡해서 의사코드 작성...을 한다고 했는데 그냥 대충쓴 코드처럼 썼다.. 이거 붙여넣고..

Coding 수업정리/CS50

CS50-02-Lab2-scrabble

https://cs50.harvard.edu/x/2023/labs/2/ Lab 2: Scrabble - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu ascii code 를 활용한 간단한 scrabble game. 아래는 제출한 답안 코드 #include #include #include #include // Points assigned to each letter of the alphabet int POINTS[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3..

Coding 수업정리/CS50

CS50-02-Section-Command line arguments

https://cs50.harvard.edu/x/2023/sections/2/ Week 2 Arrays - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu #include #include int main(int argc, string argv[]) { for (int i = 1; i < argc; i++) { printf("%c", argv[i][0]); } printf("\n"); } 출력예시 int main(int argc, string argv[]) 를 활용하면, command line argum..

Coding 수업정리/CS50

CS50-02-Section-string의 알파벳 순서 감지

https://cs50.harvard.edu/x/2023/sections/2/ Week 2 Arrays - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu #include #include #include int main (void) { string name = get_string("Type here: "); int length = strlen(name); int count = 0; for (int i = 0; i < length; i++) { if(i != 0) { if(name[i] < name[i-..

Coding 수업정리/CS50

CS50-02-Section-index

https://cs50.harvard.edu/x/2023/sections/2/ Week 2 Arrays - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu #include #include int main (void) { int length; do { length = get_int("Length :"); } while ( length < 1 ); int twice[length]; for (int i = 0, num = 1; i < length; i++, num = num * 2) { twice[i] = ..

Coding 수업정리/CS50

CS50-01-Practice Set-credit(more)

https://cs50.harvard.edu/x/2023/psets/1/credit/ Credit - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu pseudocode (의사코드) 데이터 입력 Number : = (card_number) int d_1 = (card_number % 10000000000000000) / 1000000000000000 int d_3 = (card_number % 100000000000000) / 10000000000000 int d_5 = (card_number % 10..

Coding 수업정리/CS50

CS50-01-Problem Set1-mario-more / for문 연습

https://cs50.harvard.edu/x/2023/psets/1/mario/more/ Mario - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu #include #include int main(void) { int height; do { height = get_int("Height :"); } while ( height > 8 || height < 1); for (int i = 0; i < height; i++) // i++는 { for(int j = i; j < height - 1; j++..

Coding 수업정리/CS50

CS50-01-Practice Problems-half

https://cs50.harvard.edu/x/2023/problems/1/half/ Half - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu 제출한 답안 // Calculate your half of a restaurant bill // Data types, operations, type casting, return value #include #include float half(float bill, float tax, int tip); int main(void) { float bill_amoun..

Coding 수업정리/CS50

CS50-01-Lab 1-Population growth

https://cs50.harvard.edu/x/2023/labs/1/ Lab 1: Population Growth - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu 제출한 답안 #include #include int main(void) { // TODO: Prompt for start size int start_size; do { start_size = get_int("Start size: "); } while ( start_size < 9 ); // TODO: Prompt for end size ..

Coding 수업정리/CS50

CS50-01-Practice problems-prime numbers

https://cs50.harvard.edu/x/2023/problems/1/prime/ Prime - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu 제출한 답안 #include #include bool prime(int number); int main(void) { int min; do { min = get_int("Minimum: "); } while (min = max); for (in..

기타 - 분류중

Loops

while (true). = forever while (boolean-expr). =repeat until false ( 얼마나 작동할지 모르고, 작동 안할수도 있는 것; 게임등) do while. (boolean-expr). : 무조건 1번이상 작동 보장 (한번은 작동 보장(사용자에게 요청할때 많이 씀; 한번은 요청해야 하므로)) for (int i = 0; i < 10; i++). : 10번 반복 (시작; 조건; 증가/감소) (특정 숫자만큼 작동시키고 싶으나 그 횟수를 컴파일 시점에 모를때)

기타 - 분류중

CS50-05-Data Structure / 작성중 56:00

take … for granted ①…을 당연한 것이라고[의심할 여지가 없다고] 생각하다 https://cs50.harvard.edu/x/2023/weeks/5/ Week 5 Data Structures - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu 자료 https://okeybox.tistory.com/176 Queue : 식당 줄 비슷. first in first out FIFO enqueue : 줄에 입장 dequeue : 순서가 되어서 줄에서 나감 Stack : 쌓아둔 쟁반과 비슷. las..

Coding 수업정리/CS50

CS50-04-Memory

https://cs50.harvard.edu/x/2023/weeks/4/ Week 4 Memory - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu allocate 떼어놓다 할당하다 prompt 촉진하다, 자극하다 16진수 (Hexadecimal) 8bits = 1byte (0x00(0)~FF(255)) binary (2) in bits 0000 0000 1111 1111 decimal (10) 0 255 hexadecimal (16) 00 FF 0 1 2 3 4 5 6 7 8 9 a b c d e ..

Coding 수업정리/CS50

CS50-03-Algorithms

https://cs50.harvard.edu/x/2023/weeks/3/ Week 3 Algorithms - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu linear search For each door from left to right If 50 is behind door Return true Return false //아래와 같이 의사코드(슈도코드) 작성 For i from 0 to n-1 If 50 is behind doors [i] Return true Return false binary s..

Coding 수업정리/CS50

CS50-02-Arrays

https://cs50.harvard.edu/x/2023/weeks/2/ Week 2 Arrays - CS50x 2023 Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. cs50.harvard.edu tedious 지루한 exploit 이용하다 obnoxious 불쾌한 stipulate -을 규정하다 cipher 암호 code hello.c (생성) make hello (컴파일) ./hello (실행) 컴파일러 C언어 -> clang 원레 clang -o hello.c hello -lcs50 이지만, 줄여서 make hello 로 표현한다. 컴파일 과..

kthdev
'분류 전체보기' 카테고리의 글 목록 (8 Page)