목록Computer science (7)
프랙티스만이 살길. 프랙티스만이 살길.
안전하게 배열의 크기를 키우기 위해 새로운 공간에 큰 크기의 메모리를 다시 할당하고 기존 배열의 값들을 하나씩 옮겨줘야한다 이런 작업은 O(n), 즉 배열의 크기 n만큼의 실행 시간이 소요된다. 연결리스트 데이터 구조는 우리가 컴퓨터 메모리를 더 효율적으로 관리하기 위해 새로 정의하는 구조체이다. 일종의 메모리 레이아웃, 또는 지도이다. 연결리스트는 이러한 데이터 구조중 하나이다. 배열에는 각 인덱스의 값이 메모리상에 연이어 저장되어있다. 연결리스트는 각 인덱스의 메모리 주소에 자신의 값과 다음 인덱스값의 주소를 저장한다. 연결리스트 구현 #include #include //연결 리스트의 기본 단위가 되는 node 구조체를 정의합니다. typedef struct node { //node 안에서 정수형 값..
16진수 컴퓨터과학에서는 숫자를 10진수나 2진수 대신 **16진수(Hexadecimal)**로 표현하는 경우가 많습다. 컴퓨터에서 데이터를 처리하기 위해 16진수를 사용할 때 장점이 있기 때문이다. 2개의 16진수는 1byte의 2진수로 변환되기 때문에 정보를 표현하기 매우 유용하다. 메모리 주소 정수형 변수 n에 50이라는 값을 저장하고 출력한다고 생각해 보자. 이 n 이라는 값은 int 타입이므로, 컴퓨터의 메모리 어딘가에 4바이트 만큼의 자리를 차지하며 저장되어 있다. C에서는 변수의 메모리상 주소를 받기 위해 '&’이라는 연산자를 사용할 수 있다. #include int main(void) { int n = 50; printf("%p\\n", &n); } 위와 같은 코드를 실행하면 ‘0x7ffe..
make나 clang을 사용할 때, 4가지 단계를 거칩니다. 전처리(Precompile) 첫 번째 단계는 전처리인데, 전처리기에 의해 수행된다. # 으로 시작되는 C 소스 코드는 전처리기에게 실질적인 컴파일이 이루어지기 전에 무언가를 실행하라고 알려준다. 예를 들어, #include는 전처리기에게 다른 파일의 내용을 포함시키라고 알려줍니다. 프로그램의 소스 코드에 #include 와 같은 줄을 포함하면, 전처리기는 새로운 파일을 생성하는데 이 파일은 여전히 C 소스 코드 형태이며 stdio.h 파일의 내용이 #include 부분에 포함됩니다. 컴파일(Compile) 컴파일러라고 불리는 프로그램은 C 코드를 어셈블리어라는 저수준 프로그래밍 언어로 컴파일한다. 어셈블리는 C보다 연산의 종류가 훨씬 적지만, ..
C언어 C언어는 오래되고 전통적인 순수 텍스트 기반의 언어이다. #include int main(void) { printf("hello, world\\n"); } int main(void)는 시작한다의 의미를 가지고있고, 뒤에 {}중괄호에 코드를 작성한다. stdio.h는 “stdio.h”라는 이름의 파일안에 printf라는 함수를 찾아서 접근 할 수 있도록 해준다. C언어로 작성한 코드를 “name.c”로 저장해야한다. 컴파일러 위 처럼 작성된 코드를 **“소스코드”**라고 부른다. 이를 2진수로 작성된 **“머신코드”**로 변환하면 컴퓨터가 이해할 수 있다. 이 작업을 컴파일러라는 프로그램이 수행해준다. clang은 코드를 컴파일하는 프로그램의 이름이다. 터미널에 clang name.c라는 명령어를 ..
컴퓨터 과학 문제해결을 위한 학문으로, 문제해결은 입력(input)을 받아 출력(out put)을 만드는 과정이다. 2진법 0과 1로 수를 표현하는 것. 컴퓨터는 이진법을 이용한다. 컴퓨터의 수많은 트렌지스터가 on/off 상태를 이용하여 0과 1을 표현한다. 2진법에서 하나의 자릿수를 표현하는 단위를 비트(bit)라고한다. 비트는 binary digit의 줄임말로서, 0과 1 중 하나만 가질 수 있는 측정단위이다. 바이트(byte)는 8개의 비트가 모여 만들어진 것이다. 하나의 비트에는 0과 1이 들어갈 수 있고, 여덟자리가 있기 때문에 $2^8$개의 서로 다른 바이트가 존재 할 수 있다.비트와 바이트 ASCII 컴퓨터는 0과1밖에 사용하지 않기 때문에 문자를 숫자로 표현하기 위해서는 0과1의 조합으로..