본문 바로가기

Doc/컴퓨터

컴퓨터과학 CS50 2020 Lecture 2 : Arrays

 

 

 

 

<강의 필기>

 

 

Compiler
프로그래밍 코드를 기계가 이해할 수 있는 이진 기계어로 번역한다.

 

Clang

C, C++, 오브젝티브-C, 오브젝티브-C++ 프로그래밍 언어를 위한 컴파일러 프론트엔드이다.
함수에 있는 코드를 실행한다.

compiling의 4단계
preprocessing. compiling. assembling. linking

preprocessing
#include <stdio.h>의 의미 -> int print(string format, )
원형이 되는 함수 코드를 입력시킨다.
무엇을 작동시킬지 모르지만 환경을 만들어준다.


compling
preprocessing에서 입력한 코드가 assembly code로 번역된다.


assembling

assembly code가 object code로 번역된다.
low level code of _main. get_string
컴퓨터가 이해하는 단계의 밑바닥 low level로 간다.
파이썬 같은 언어는 high level code이다.

linking
machine code는 0과 1의 모음이 결합되는 것이 컴퓨터를 나타내는 언어이다.

 

 

 

 



CS50 IDE
cloud shell 안에 컴파일러는 내장되어 있다.
.h .c가 뒤에 붙는 라이브러리를 사용한다.

stdio.c는 시스템에 내장되어 있지 않다.
코드를 입력해서 linking시키면 패키지와 모듈을 만들 수 있다.
assembling과 preprocessing은 low-level에서 알아서 해준다.


help50
에러메시지를 해석하는데 도움이 되는 도구

style50
사람이 읽기 좋은 코드 만들기

check50
즉각적인 피드백을 줘서 디버깅을 하는다.

 

debug50
컴퓨터의 변수와 메모리가 작동하는 과정을 들여다본다.
천천히 step by step으로 탐색한다.
debug50은 line6에 코드 실행을 중단한 것을 노란색 줄로 보여준다.

 

 

 

 

 

 

debug

 

printf
프로그램의 작동 상태를 메시지로 전달하는 print stuff이다.
대화하듯이 debugging을 말해주는 문장

 


I is now 0
#
I is now 1
#
...
I is now 10
#




...

int get_negative_int(void)
{
    int n;
    do
    {
        n = get_int("Negative Integer: ");
    }
    while (n < 0);
    return n;
}

 



Call Stack
Excuting하는 Function과 Main 상황 보여준다.

Debugger가 loop의 잘못에 대한 힌트를 주는가?
Boolean Gate를 작동시키라고 한다.

 

 





Memory
bool 1 byte
char 1 byte
double 8 bytes
float 4 bytes
int 4 bytes
long 8 bytes
string ? bytes
...

 

 

RAM(Random Acess Memory)
파일을 열고 프로그램을 돌리는 데 사용한다.

 


Chip
byte가 physical device에 내장된다.
grid의 byte가 메모리를 구성한다.

 

int score = 72
int score = 73
int score = 33

72, 73, 33 integer는 memory의 bytes의 grid를 각자의 영역에 맞게 채워간다.

 

 

 

 

 


Arrays

arrays는 sequence of values이다.


scores[0]
출발점이 0이라서 zero-indexing을 한다. 


scores[i]
loop에서 변수로 쓰여서 짧은 코드를 쓸 수 있게 한다.

 

 

 

 

 

 

string 
C언어에는 기술적으로 string 자료형이 존재하지 않는다.
그러나 CS50의 라이브러리에는 예외적으로 string 자료형을 추가했다.


Between Uppercase and Lowercase is 32.
s[i] - 32) = touuper() function = From Lowercase to Uppercase Transformer

 

 

 

 

 


argc. argv
argc는 argument count를 말한다.
명령으로 불러들인 변수들의 개수를 센다.

argv는 argument vector를 말한다.
vector는 list를 표현하는 또다른 방법이다.


...

int main(int argc, string argv[])
{
    if (argc == 2)
    {
        printf("hello, %s\n", argv[1]);
    }
    else
    {
        printf("hello, world\n");
    }
}

 


./argv Brian
Hello, Brian

./argv Brain Yu
Hello, world

argv[1][i]
arrays of array

 

 

 


cryptography
readability는 cryptography와 관련있다.
plaintext -> cipher -> ciphertext
I LOVE YOU -> J MPWF ZPV
 

 

 

 

 

 

강의 자료

 

Week 2 - CS50

Introduction to the intellectual enterprises of computer science and the art of programming. This course teaches students how to think algorithmically and solve problems efficiently. Topics include abstraction, algorithms, data structures, encapsulation, r

cs50.harvard.edu

 

 

 

CS50 Sandbox

 

CS50 Sandbox

Temporary programming environments for students and teachers.

sandbox.cs50.io

 

 

 

Be sure to drink your Ovaltine | A Christmas Story | TBS

 

 

Annie’s Secret message for you members of the secret circle

"Be sure to drink your Ovaltine."

Ovaltine? Crummy Commercial

 










>