-
Types, format codes, operators | CS 50 Week 1Computer Science/CS 50 Harvard 2021. 11. 6. 19:15
CS 50 Fall 2021 강의를 정리한 것 입니다.
Types
Variables를 이용하려면 다양한 Type들이 존재한다. 이런 type들을 이용해서 데이터를 나타낼 수 있다.
- bool, a Boolean expression of either true or false
- true인지 false인지 나타내는 bool, 또는 Boolean expression
- char, a single character like a or 2
- a, 2, $ 와같은 하나의 캐릭터를 나타내는 char
- double, a floating-point value with more digits than a float
- 소수점을 나타낼 수 있고, float보다 더 많은 자리를 나타낼 수 있는 double
- float, a floating-point value, or real number with a decimal value
- 소수점까지 나타낼 수 있는 float
- int, integers up to a certain size, or number of bits
- 정수를 어느정도 크기까지 나타낼 수 있는 int
- long, integers with more bits, so they can count higher than an int
- int보다 더 많은 정수를 나타낼 수 있는 long
- string, a string of characters
- 말그대로 string of characters, 즉 여러가지 문자를 엮은 string.
이 이외에도 여러가지 타입이 존재한다.
CS 50 Library
CS 50 Library를 이용하면, 이러한 type들을 input으로 받아서 사용할 수 있는 아래와 같은 funcitons, 함수들을 사용할 수 있다.
- get_char
- get_double
- get_float
- get_int
- get_long
- get_string
이 이외에도 다양한 함수들이 존재한다.
printf
printf에서 어떤 값들을 프린트할 때, 다양한 값들을 넣어줄 수 있는데, 아래와같은 format codes를 사용할 수 있다.
- %c for chars
- %f for floats or doubles
- %i for ints
- %li for long integers
- %s for strings
Operators
프로그래밍을 위해서는 여러가지 계산이 필수적인데, 아래와 같은 수학기호들이 존재한다.
- + for addition (덧셈)
- - for subtraction (뺄셈)
- * for multiplication (곱하기)
- / for division (나누기)
- % for remainder (나머지)
Reference
'Computer Science > CS 50 Harvard' 카테고리의 다른 글
Calculations | CS50 Week 1 (0) 2021.11.06 Variables, syntactic sugar | CS50 Week 1 (0) 2021.11.06 main, header files, commands | CS 50 Week 1 (0) 2021.11.06 Functions, arguments, return values, variables | CS50 Week 1 (0) 2021.11.05 IDEs, compilers, interfaces | CS50 Week 1 (0) 2021.11.04 - bool, a Boolean expression of either true or false