printf("ho_tari\n");

C언어(1) 본문

(Telechips) AI 시스템 반도체 SW 개발자 교육/C

C언어(1)

호타리 2025. 2. 18. 16:27

2025.02.18

 

교재 : 혼자 공부하는 C언어

 

언어


- 기계어, 어셈블러

  • 기계어 : 1011 0110 1000 1110
  • 어셈블러 : LD R3, 10

- 컴파일언어

  • 컴파일러를 이용하여 일괄 변환
  • C, Pascal, C++, C#, Java

- 스크립트언어

  • 인터프리터를 이용하여 한줄씩 변환하여 실행
  • Basic, Python, Javascript, Perl, Skill

*.c → Compile → *.o - Link → *.exe(Window), *.elf(Linux), *.hex

 

 

주석처리 단축키 : ctrl + / 또는 ctrl + shift + /

 

 

1. 소스 작성

 

- 알고리즘의 각 단계를 프로그래밍 언어를 이용하여 기술

- 알고리즘을 프로그래밍 언어의 문법에 맞추어 기술한 것을 소스 프로그램이라고 한다.

- 소스 프로그램은 주로 텍스트 에디터나 통합 개발 환경을 이용하여 작성한다.

 

2. 컴파일

 

- 소스 프로그램을 오브젝트 파일로 변환하는 작업

 

3. 실행 및 디버깅

 

- 소스에 존재하는 오류 찾기

 

→ IDE (Integrated Development Environment) 통합 개발 환경 (예 : visual studio, eclipse, Dev-C++, etc)

 

구조 : solution - projects - files

 

#include : 소스 코드 안에 특정 파일을 현재의 위치에 포함

<stdio.h> : 헤더 파일 - 컴파일러가 필요로 하는 정보를 가지고 있는 파일 (stdio.h = standard input output header file)

 

프로그램 = 함수의 집합

 

Bit : 정보를 표시하는 최소 단위

Byte : 정보를 모아서 구분할 수 있는 단위

 

8bit

16bit

32bit

64bit

 

 

float and double

32bit : MSB, 부호(1bit) + 지수(8bit) + 가수(23bit), LSB

 

/*
프로그램 제목 : Hello World
저자 : Steve
날짜 : 2025년 2월 18일
*/
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include <math.h>

/*
// 함수 정의 prototype
void sub();

// 이것은 메인 함수입니다.
void main(void) {
	// 함수 호출
	sub();
	return 0;
}

// 이것은 보조 함수를 구현한 것입니다.
void sub() {
	printf("Hello world\n");
	printf("Hello \nworld\n");
	printf("Hello \rworld\n");
	printf("Hello \tworld\n");
	printf("Hello \bworld\n");
	printf("Hello \"\\n\"world\n");
	printf("Hello\a \nworld\n");
}
*/

/*
void main(void) {
	printf("%d\n", 100+1);
	printf("%f\n", 12.34);
	printf("%X\n", 128);
	printf("%d = %X\n", 128, 128);
	printf("%d = %X\n", 0x7f, 0x7f);
	printf("%d, %X\n", 0b11010111, 0x7f);
	printf("%d, %X\n", -50, -0x7f);
	printf("%d, %X\n", -50, -1);
	printf("%d, %X\n", -50, -1);
}
*/

/*
void main(void) {
	printf("%c\n", 65);
	printf("%c\n", 0x41);
	printf("%c, %d\n", 0x41, 'A');
	printf("%c, %c\n", 0x41, 'A');
	printf("%s는(은) 스트링입니다.\n", "string");
}
*/

/*
void main(void) {
	char a; // 문자를 저장하기 위한 변수형, -128 ~ +127, 8bit
	unsigned char aa; // 부호가 없는 char, 0 ~ 255
	int b; // 정수를 저장하기 위한 변수형, bit : 컴퓨터에 따라 가변적(32bit : -20억 ~ +20억)
	long c; // int의 2배
	float d; // 소수, 실수를 저장하기 위한 변수형, int와 같은 bit
	double e; 

	printf("size = %d\n", sizeof(char));
	printf("size = %d\n", sizeof(unsigned char));
	printf("size = %d\n", sizeof(int));
	printf("size = %d\n", sizeof(long));
	printf("size = %d\n", sizeof(float));
	printf("size = %d\n", sizeof(double));
	printf("size = %d\n", sizeof(short));
}
*/

/*
void main(void) {
	char str[12] = { "Hello world" };
	char str2[12];
	printf("%s\n", str);
	str[5] = 0;
	strcpy(str2, str);
	printf("%s\n", str);
	printf("%s\n", str2);
}
*/

/*
void main(void) {
	const int a = 1234; // 상수 const로 정의된 것은 RAM영역에 할당되지 않고 ROM영역에 code형태로 존재
	printf("%d", a);
}
*/

/*
void main(void) {
	int a;
	char name[20];
	printf("나이를 입력하세요.\n");
	scanf("%d", &a);
	printf("이름을 입력하세요.\n");
	scanf("%s", name);
	printf("%s님의 나이는 %d살입니다.", name, a);
}
*/

/*
int main() {
	int a = 3 + 2;
	int b = 3 - 2;
	int c = 3 * 2;
	int d = 3 / 2;
	int e = 3 % 2;
	printf("3 + 2 = %d\n", a);
	printf("3 - 2 = %d\n", b);
	printf("3 * 2 = %d\n", c);
	printf("3 / 2 = %d, %d\n", d, e);
}
*/

/*
int main() {
	int a = -1;
	int b;
	b = -a;
	printf("%d", b);
}
*/

/*
int main() {
	float a;
	int b, c;
	a = 5.0 / 2.0;
	b = 5 / 2;
	c = 5 % 2;
	printf("%.1f, %d, %d\n", a, b, c);
	printf("%.2f\n", a);
	printf("%3d\n", b);
	printf("%d\n", c);
}
*/

/*
int main() {
	unsigned char a;
	unsigned char b;
	a = 255;
	b = 0;
	a = a + 1;
	b = b - 1;
	printf("%d\n", a);
	printf("%d\n", b);
}
*/

/*
int main() {
	unsigned char a, b, c;
	a = 0;
	b = 0;
	c = 0;
	a++;
	b--;
	++c;
	printf("%d\n", a);
	printf("%d\n", b);
	printf("%d\n", c);
}
*/

/*
void sub(unsigned char b) {
	printf("S = %d\n", b);
}

int main() {
	unsigned char a;
	a = 9;
	// sub(++a);
	sub(a++);
	printf("M = %d\n", a);
}
*/

/*
int main() {
	// 관계연산자 : <, >, >=, <=, ==(같다), !=(다르다)
	printf("%d\n", 4 < 5); // 참은 1
	printf("%d\n", 4 > 5); // 거짓은 0
}
*/

/*
int main() {
	char a = 4;
	char b = 5;
	printf("%d\n", (4 < 5) && (a > b)); // (4 < 5)는 참, (a > b)는 거짓, &&는 논리곱이므로 1 && 0은 0, and 연산자
	printf("%d\n", (4 < 5) || (a > b)); // (4 < 5)는 참, (a > b)는 거짓, ||는 논리합이므로 1 || 0은 1, or 연산자
}
*/

int main() {
	printf("%d\n", 5 | 6); // 5와 6을 이진수로 바꿔서 or 연산
	printf("%d\n", 5 & 6); // 5와 6을 이진수로 바꿔서 and 연산
	printf("%d\n", 5 >> 1); // shift 연산자, 5 = 0101을 오른쪽으로 shift, 오른쪽으로 shift 1은 나누기2
	printf("%d\n", 5 << 1); // shift 연산자, 5 = 0101을 왼쪽으로 shift, 왼쪽으로 shift 1은 곱하기2
}

0218.c
0.00MB

'(Telechips) AI 시스템 반도체 SW 개발자 교육 > C' 카테고리의 다른 글

C언어(5)  (0) 2025.02.24
C언어(4)  (0) 2025.02.21
C언어(3)  (0) 2025.02.20
C언어(2)  (0) 2025.02.19