Computer Science 387

C언어 8강 | 전처리기 Preprocessors

preprocessor #include #define이 대표적 use of #include #include #include #include "filename" : 직접 만든 것 (파일 경로 일치해야 함) use of #define #define identifier token_string #define SECONDS_PER_DAY (60*60*24) #define PI 3.141592 #define C 299792.458 #define EOF -1 #define MAXINT 2147483647 macros with arguments #define SQ(x) ((x)*(x)) #define SQ(x) x*x #define SQ(x) (x) * (x) 셋 다 다른 표현임 주의 #define min(x, y) ..

Computer Science/C 2021.12.17

C언어 7강 | Bitwise operators

중요한 부분 : enum, bit로 출력하기, Bitwise operation bitwise logical operator complement : ~ AND : & OR : | XOR : ^ // example #include int main() { unsigned char num1 = 1; //0000 0001 unsigned char num2 = 3; //0000 0011 printf("%d\n", num1&num2); // 0000 0001 printf("%d\n", num1|num2); // 0000 0011 printf("%d\n", num1^num2); // 0000 0010 return 0; } bitwise shift operator left shift : shift 연산자는 두번째 피연산..

Computer Science/C 2021.12.17

C언어 10강 | Structures and list processing | 제일 중요함 ***

매우 중요함 linear linked list stack queue binary tree structures and list processing self referential structures 자기 자신을 가리키는 포인터 변수를 멤버로 갖는 구조체 struct list { int data; struct list *next; }; struct list a, b, c; a.data = 1; b.data = 2; c.data = 3; a.next = &b; b.next = &c; c.next = NULL; printf("%d\n%d\n", a.next->data, a.next->next->data); linear linked lists 배열은 배열인데, struct가 일렬로 연결된 리스트(꼬리잡기) #inc..

Computer Science/C 2021.12.17

C언어 9강 | 구조체 Structures

Structures array 배열과 structure 구조체의 차이는? array는 동질적인 type의 데이터를 묶어서 보여주기 위해 사용하는 것이라면, structure는 여러 타입의 변수를 통합하여 보여주기 위해 사용한다. struct랑 typedef가 자주 묶여서 사용된다. 아래는 그 예시들 struct card{ int pips; char suit; }; typedef struct card card; card c1, c2; card c1, c2로 선언한 아이들의 pips, suit(멤버)에 접근하려면, c1.pips, c2.suit와같이 .을 이용하면 된다. 멤버의 네임은 달라야 한다. struct fruit { char *name; int calories; }; typedef struct fr..

Computer Science/C 2021.12.17

C언어 6강 | Arrays, Pointers, and Strings | 중요!

One dimensional arrays array 배열 선언하는 법 : type array_name[size]; array initialization 배열 초기화 array는 storage class가 auto, external, static일 수 있다(register는 안됨) auto인 경우에는 선언만 해주면, 쓰레기값이 들어있으므로꼭 초기화를 해주어야 한다. float f[5] = {0.0, 1.0, 2.0, 3.0, 4.0}; int a[100] = {0}; int a[] = {2,3,5,-7}; array subscripting 배열 첨자 a[i]로 배열 요소에 접근한다. sorting 배열을 이용하여, 4,-681,52,-23,15,9,13을 정렬하는 프로그램을 짜보자. 1) bubble so..

Computer Science/C 2021.12.16

C언어 4강 | Flow of Control | 반복문, 조건문, 순차 구조

제어 구조 Flow of control 프로그램은 보통 순차 제어 구조로 진행된다. sequential flow of control 그런데 어떤 경우에는 선택, 반복 구조를 차용해야 할 때가 있다. 선택 구조 : a choice of action if, if-else, switch 반복 구조 : repetition while, for, do Relational, Equality, Logical operators true인 경우 nonzero value false인 경우 zero value 리턴함 relational : = equality : == != logical operators : && || Relational operators and expressions = 등이 있다. 만약 (a < ..

Computer Science/C 2021.12.16

C언어 3강 | 데이터 타입 | char, int(short, long,unsigned), float, typedef

Declaration, Expression, Assignment Declarations 선언 변수 Variables와 상수 constants는 반드시 사용되기 전에 선언되어야 한다. 선언에서는 [1] 변수와 type을 연결짓고 [2] 컴파일러로 하여금 특정한 양의 메모리를 잡아두도록 한다. #include int main(void){ int a, b, c; float x, y = 3.3, z = -7.7; printf("Input two integers: "); scanf("%d%d", &b, &c); a = b+c; x = y+z; } Expressions 함수, 변수, 연산자, 상수 등을 조합하여 만들어진다. assignment statement variable = expression; 기본적인 데이..

Computer Science/C 2021.12.16

C언어 2강 | 어휘 요소와 연산자 Lexical Elements & Operators

컴파일러 Compiler C code의 적법성을 판단함 C code를 object code로 변환한다. C Program compiler는 C 프로그램에서 6 가지 token을 모은다. keywords identifiers constants string constants operators punctuators Characters used in a C prog abcde ABCDE 12345 +-*/=(){}[]''"" !#%_|^~\.,;:? etc 주석 Comments // /* */ Keywords 특정한 의미를 나타내는데 사용되는 keywords는 다른 맥락으로 사용할 수 없다. C는 가벼운 언어라 keywords가 상대적으로 적다. auto, do, goto, signed, unsigned, br..

Computer Science/C 2021.12.15

C 언어 1강 | 알고리즘 사고, C 언어 역사, Hello World!

🐱‍🐉 프로그래밍 서론 🐱‍🚀 알고리즘적인 사고 프로그래밍에서 알고리즘은 마치 요리할 때 레시피와 같은 역할을 한다. 알고리즘 사고를 한다는 것은 [1] 컴퓨터가 이해 가능한 형태로 표현하고, [2] 가능한 모든 경우를 포괄하도록 알고리즘을 설계한다는 것이다. 본 노이만 아키텍처 컴퓨터는 본 노이만 아키텍처를 따라서 디자인된다. 본 노이만 아키텍처는 존 폰 노이만(1903~1957, 헝가리 출신 수학자)이 설계한 것으로, Stored Program concept라고 한다. Stored Program Concept는 컴퓨터 내부에 기억 장치를 갖추고(메모리) 계산의 순서를 부호화하여 순차적으로 처리하고(CPU), 해독한 후에 실행하는 것을 기본 구조로 한다. 이때 첫번째 단계는 Fetch : CPU 내부로..

Computer Science/C 2021.12.14

singly linked list

이번주 과제 - singly linked list 구현하기 Singly linked list node를 사용하여 구현한 리스트인데 array list와 달리, 엘리먼트 간의 연결 link을 이용해서 리스트를 구현한 것이다. array list는 각 요소를 element라고 하지만, linked list에서는 node, vertex라고 한다. 장점 : 동적으로 메모리 사용 가능함 메모리를 효율적으로 사용할 수 있다. 데이터 재구성이 용이하다. 대용량 데이터 처리하는 데 적합하다. Node typedef struct Node{ int data; Node *next; } Node; 구성요소 1. 사용자가 추가한 데이터 내용 구성요소 2. 다음 노드와의 연결 cf. 마지막 노드는 NULL로 저장한다. → 배열 ..