본문 바로가기

웹_프론트_백엔드/JAVA프레임윅기반_풀스택

2020.07.08

1. Visual Studio 다운

: 구글에 visual studio 검색

> https://visualstudio.microsoft.com/ko/ > Community 버전으로 다운(Community 버전만 무료로 사용할 수 있음)

 

 

2. 학원에서는 이미 다운로드된 2015 버전 사용할 예정

** 계정 등록 완..!!

 

 

3. Visual Studio에서 GitHub 사용하기

 : 도구 > 옵션 클릭

> 소스 제어 > 플러그 인 선택 > Git 선택 후 확인 버튼

> 팀 > 연결관리(N)... 클릭 > 팀 탐색기창 뜸

> GitHub 연결 버튼 클릭하면 로그인 창 뜸 > 로그인

> 복제 클릭 > 원하는 repositories 선택 후 Clone 클릭, [이때] repositories 선택하는 과정 중에 로컬 경로로 설정 가능!!

 

 

4. 솔루션 생성

 : 솔루션 > 새로만들기 클릭 > 새 프로젝트 창 뜨면서 솔루션 생성과 첫번째 프로젝트 생성 가능

 

 

5. c파일 만들기

 : 생성된 프로젝트 확인 후 솔루션탐색기 탭으로 넘어가기

> 소스 파일 > 추가 > 새항목 클릭

> C++ 파일 선택 > 이름.c로 무조건 확장자 c로 작성 후 추가 버튼 클릭

 

 

6. C_Work > 01_Hello > 101_HelloWorld.c

#include <stdio.h>

int main()
{
	printf("Hello World\n");
	printf("안녕하세요\n");
	getchar();
}

 

 

7. 자바는 하나의 프로젝트 안에 여러 개의 메인 가능(객체 지향이기 때문에)하나
    C는 하나의 프로젝트에 하나의 메인만 가능(절차 지향이기 때문에)하다.

** 여러 개의 메인이 있을때 에러 발생!!

[해결책] 메인을 하나만 남기고 모두 빌드에서 제외시킨다.

 

 

8. C_Work > 01_Hello > 102_welcome.c

#include <stdio.h>

int main()
{
	printf("오늘은 %d/%d 입니다 \n", 7, 8);
	getchar();
}

 

 

9. 새 프로젝트 추가

 : 솔루션 선택 후 우클릭 > 추가 > 새 프로젝트 클릭

> 빈 프로젝트 선택, 프로젝트 이름 설정 후 확인 버튼 클릭 > 프로젝트 생성 완...!!

 

 

10. 시작 프로젝트를 현재 선택 영역으로 설정 변경

 : 솔루션 선택 후 우클릭 > 속성

> 공용 속성 > 시작 프로젝트 > 현재 선택 영역 선택 후 확인 클릭

> 솔루션 탐색기를 확인해보면 현재 선택 영역이 시작 프로젝트로 선택되어 있음

   (시작 프로젝트는 글자가 bold되어 있음)

 

 

11. C_Work > 02_Variable > 201_variable1.c

#include <stdio.h>

int main() 
{
	int a;
	int mike, jane;
	a = 100;
	printf("a = %d\n", a);

	// 초기화되지 않은 지역변수를 사용했기 때문에 에러 발생함
	printf("mike = %d\n", mike);
	printf("jane = %d\n", jane);

	getchar();
}

 

 

12. C_Work > 02_Variable > 202_variable2.c

#include <stdio.h>
/*
	C언어의 데이터 타입
	 char	: 1byte, 문자하나
	 short	: 2byte  정수
	 int	: 4byte   정수
	 long	: 4byte   정수 (시스템마다 다름)
	 float	: 4byte  실수
	 double	: 8byte 실수
*/
int main() 
{
	// C언어에서는 Long 타입의 리터럴 하지않아도 에러나지 않는다
	long l1, l2 = 1234567890;
	char ch1 = 'a';

	// char (1byte)
	printf("ch1 = %c\n", ch1);
	printf("ch1 = %d\n", ch1);

	// char 범위 : -128 ~ +127
	// unsigned char : 0 ~ 255

	unsigned char ch2 = 255;
	printf("ch2 = %d\n", ch2);

	getchar();

}

 

 

13. C_Work > 02_Variable > 203_constant.c

#include <stdio.h>

/*
	상수 (Constant)
	 한번 값이 정해지면 변경할수 없는 데이터
	 (변수의 반대)

	 방법1 : const 키워드 사용
	 방법2 : #define 사용
*/
#define MAX_VALUE 100

int main()
{
	const int N = 10;
	//N = 20;
	printf("N = %d\n", N);
	printf("MAX_VALUE = %d\n", MAX_VALUE);

	getchar();
}

/*
	#define
	#include
	#ifndef
	#...

	# : 전처리기(preprocessor)
*/

 

 

14. C_Work > 03_InputOutput > 301_ouput.c

#include<stdio.h>

int main()
{
	//String str = "Hello";

	// 문자열 변수
	// 최대 20개의 문자를 담을 수 있는 char 배열 <-- 문자열을 담는다
	char str1[20] = "C language";

	// %s : 문자열 출력
	printf("str1 = %s\n", str1);

	char str2[] = "Java language";	// 자동으로 초기화, 문자열의 문자 개수만큼의 크기로 생성
	char* str3 = "Python language";	// 포인터 사용

	printf("str2 = %s\n", str2);
	printf("str3 = %s\n", str3);

	getchar();

}	

 

 

15. C_Work > 03_InputOutput > 302_input.c

#include<stdio.h>
#pragma warning(disable:4996)

int main()
{
	int kor, eng, math;
	printf("국어점수 입력 : ");
	scanf("%d", &kor);		// 정수 한 개 입력 -> kor  변수에 대입
									// 변수명 앞에 & 붙이기!
	printf("영어점수를 입력하세요 : ");
	scanf("%d", &eng);
	printf("수학점수를 입력하세요 : ");
	scanf("%d", &math);

	printf("입력하신 점수는 %d, %d, %d 입니다\n", kor, eng, math);

	getchar();
	getchar();
}

 

 

16. 템플릿 만들기(main.c)

 : 파일 > 템플릿 내보내기(E)... 클릭 > 템플릿 내보내기 마법사 창 뜸 > 항목 템플릿 선택 후 다음 클릭

> main.c 파일 선택 후 다음 클릭

> 템플릿 이름, 설명 설정 후 마침 클릭하면 템플릿 만들기 완...!!

 

 

17. 만든 템플릿을 이용하여 파일 생성

 : 템플릿 등록 후 템플릿 등록을 위해 만든 파일 삭제

> 소스파일 선택 후 우클릭 > 추가 > 새 항목 클릭

> 아래의 사진과 같이 등록한 main 템플릿이 확인될 것임...!!

> 등록된 템플릿 선택 후 이름도 변경하지 말고 추가 버튼 클릭

> 템플릿을 이용한 파일 생성 완...!!

> F2 단축키 이용, 원하는 이름으로 변경하기

 

 

18. C_Work > 03_InputOutput > 303_input.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

/**

**/

int main(int argc, char** argv)
{
	// scanf() 동시에 여러 데이터 입력 가능
	int a, b, c;
	printf("정수 3개 입력하세요 : ");
	scanf("%d %d %d", &a, &b, &c);
	printf("입력값 A = %d, b = %d, c = %d\n", a, b, c);

	printf("또 정수 3개 입력하세요 : ");
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	printf("입력값 A = %d, b = %d, c = %d\n", a, b, c);

	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

19. C_Work > 03_InputOutput > 304_input.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

/**

**/

int main(int argc, char** argv)
{
	char name[20];		// 최대 20문자 담을 수 있는 문자열(char[])

	printf("이름을 입력하세요 : ");
	scanf("%s", name);	// 문자열 입력받을때는 & 붙이지 마세요

	printf("입력한 이름은 : %s", name);


	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

20. C_Work > 05_Conditional > 501_if.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

/**
	비교연산자, 논리연산자의 결과는 1, 0
	조건식에서 0이면 -> '거짓' 판정
	               0 이외의 값이면 -> '참' 판정
**/

int main(int argc, char** argv)
{
	int n = 21;
	if (n % 2 == 0) 
	{
		printf("짝수입니다\n");
	}
	else 
	{
		printf("홀수입니다\n");
	}

	if (100) { printf("참입니다\n"); }

	if (!(4 - (2 * 2))) { printf("참입니다\n"); }
	else { printf("거짓입니다\n"); }

	printf("뭐지? %d\n", !(4 - (2 * 2)));
	printf("뭐지2? %d\n", !1024);

	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

21. GitGub, commit 후 puch

 : 팀 탐색기 탭으로 이동 > 변경 내용 클릭

> 커밋 메시지 작성 후 모두 커밋 후 푸시 클릭

> GitHub에 정상적으로 push 처리 됨..!!

 

 

22. C_Work > 07_Function > 701_Function.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

#include "myfunction.h"

void myFunc(int k, int v) 
{
	printf("두 수는 %d %d 입니다\n", k, v);
	printf("합 : %d, 차 : %d, 곱 : %d\n", k + v, k - v, k * v);
}

// 동일 이름의 함수 정의 불가! -> (오버로딩 없음)
// 자바는 가능했으나 씨언어는 불가!!
//void myFunc() 
//{}

// 함수의 선언
double divByTwo(double);

int main(int argc, char** argv)
{
	myFunc(10, 20);
	myFunc(200, 100);
	myFunc(34, 2);

	printf("div결과 %f \n", divByTwo(100));

	printf("addTwo() 결과 : %d\n", addTwo(10, 20));
	printf("doubleUp() 결과 : %.1f\n", doubleUp(10.123));

	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()


// 씨언어는 함수 호출(사용)하기 전에 반드시 먼저 '정의'되어 있거나,
// 혹은 '선언'되어 있어야 한다.
// Why? one pass type이라 위에서 아래로 컴파일을 진행하기 때문!
double divByTwo(double arg)
{
	return arg / 2;
}

// 선언부는 header 파일(*.h)에 모아놓은 것이 일반적
// 정의도 별도의 C 파일(*.c)에 정의

 

[추가] 헤더 파일 추가하기

** 사용자 헤더 파일 작성(myfunction.h, myfunction.c) > 701_Function.c에서 #include"myfunction.h" 사용 가능 **

 

 : 프로젝트 선택 후 우클릭 > 추가 > 새항목 > 헤더파일 선택 후 이름 설정 > 추가 버튼 클릭

** C_Work > 07_Function > myfunction.h

#pragma once

// 헤더 파일 (*.h)
// 함수 선언, 매크로, 상수 등을 모아놓은 파일

int addTwo(int, int);
double doubleUp(double);

 

** C_Work > 07_Function > myfunction.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <time.h>
#pragma warning(disable:4996)

// 함수 정의
int addTwo(int a, int b)
{
	return a + b;
}

double doubleUp(double n)
{
	return n * 2;
}

 

 

23. C_Work > 08_Array > 801_array.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

/** 
	배열(array)
	 동일한 타입의 데이터(들)을 '하나의 배열이름' 으로 담아놓은 집합데이터
	배열 변수 선언
	 타입 배열변수명[배열크기];
	 타입 배열변수명[] = { 초기화 값(들)..};
**/

int main(int argc, char** argv)
{
	// 5개의 int 타입 배열
	int korArr[5];

	for (int i = 0; i < 5; i++)
	{
		// 초기화 안된 배열은 쓰레기값(garbage value)가 담겨 있다.
		printf("국어[%d] = %d\n", i, korArr[i]);
	}

	korArr[0] = 100;
	korArr[1] = 90;
	korArr[2] = 88;
	korArr[3] = 44;
	korArr[4] = 76;

	printf("\n");
	for (int i = 0; i < 5; i++)
	{
		printf("국어[%d] = %d\n", i, korArr[i]);
	}

	printf("\n");
	// C언어 배열 인텍스 주의!
	// 배열 인덱스 범위 벗어나도 에러 발생 안됨
	// 쓰레기값 나올뿐..!!
	for (int i = 0; i <= 5; i++)
	{
		printf("국어[%d] = %d\n", i, korArr[i]);
	}

	printf("\n");
	printf("국어[%d] = %d\n", -1, korArr[-1]);

	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

24. C_Work > 08_Array > 802_array.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

/**
	배열 초기화
**/

int main(int argc, char** argv)
{
	// 방법1 : 배열 선언과 동시에 초기화
	int arr1[3] = { 10, 20, 30 };

	for (int i = 0; i < 3; i++) 
	{
		printf("arr[%d] = %d\n", i, arr1[i]);
	}

	// 방법2 : 초기화 값의 개수가 배열의 길이보다 작다면??
	// 나머지가 0으로 초기화됨
	int arr2[3] = { 1 };

	printf("\n");
	for (int i = 0; i < 3; i++)
	{
		printf("arr[%d] = %d\n", i, arr2[i]);
	}

	// 방법3 : 배열의 길이를 선언하지 않고 초기값만으로 초기화
	int arr3[] = { 10, 20, 30 };

	printf("\n");
	for (int i = 0; i < 3; i++)
	{
		printf("arr[%d] = %d\n", i, arr3[i]);
	}


	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

25. C_Work > 08_Array > 803_size_length.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

/**
	배열의 크기(size) : 배열의 용량(byte)
	배열의 길이(length) : 배열 원소의 개수
**/

int main(int argc, char** argv)
{
	// sizeof() 연산자
	// 데이터의 크기를 byte(정수)로 리턴
	printf("%d\n", sizeof(10));	// 리터럴의 크기
	printf("%d\n", sizeof(double));	// 타입명의 크기도 가능!

	int arr[3];
	printf("sizeof(배열) : %d\n", sizeof(arr));	// 배열 이름으로 배열 크기 확인!
	printf("arr[0]의 size : %d\n", sizeof(arr[0]));	// arr[0]의 size


	// 배열의 길이 구하는 공식
	//		sizeof(배열이름) / sizeof(배열원소타입)
	//		sizeof(배열이름) / sizeof(배열의 첫번째 원소)
	printf("arr의 length = %d\n", sizeof(arr) / sizeof(int));
	printf("arr의 length = %d\n", sizeof(arr) / sizeof(arr[0]));


	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

26. C_Work > 08_Array > 804_array_str.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

/** 
	배열과 문자열
	 본질적으로 C언의 문자열은 'char 배열' 이다

	C언어에서 문자열의 끝은
	 '\0' (null 문자) 로 끝나는 'char 배열' 이다
**/

int main(int argc, char** argv)
{
	// 문자열을 선언, 초기화하는 다양한 방법들
	char str1[20] = "nice";
	char str2[] = { 'n', 'i', 'c', 'e', '\0' };
	char str3[] = "nice";
	char* str4 = "nice";

	// %s : '\0' (null 문자)로 끝날때까지 출력한다.
	printf("str1 = %s\n", str1);
	printf("str2 = %s\n", str2);
	printf("str3 = %s\n", str3);
	printf("str4 = %s\n", str4);

	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

27. C_Work > 08_Array > 805_ndim.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

/**
	다차원 배열 (n-dimensional array)
	 배열 첨자(index)를
	 하나 사용하면 --> 1차원 배열
	 두개 사용하면 --> 2차원 배열
	 ...
**/

int main(int argc, char** argv)
{
	// 2차원 배열 선언
	int array[4][3] = { 0 };	// 4 x 3

	for (int i = 0; i <4; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			printf("arr[%d][%d] = %d\n", i, j, array[i][j]);
		}

	}

	// 문자열 배열. char[][]
	char str[4][20] = {
		"hello",
		"myworld",
		"c-world",
		"장윤성"
	};

	for (int i = 0; i < 4; i++) {
		printf("str[%d] = %s\n", i, str[i]);
	}


	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

28. C_Work > 09_Pointer > 901_pointer.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

/** 
	포인터1 : 주소연산자
	 메모리
		연속된 1byte 단위들의 공간
		1 byte 단위로 데이터를 저장된다.
		각 byte 데이터는 고유한 주소값을 통해 접근 가능
		 ex) int 값은 4byte 이므로 '연속된' 1byte x 4개 공간에 저장된다.
	 주소
		: Windows 환경에선 주소는 4byte.  (Mac 이나 Linux 에선 8byte);
	 주소연산자 : &
		변수가 저장된 주소값을 리턴하는 연산자
		int 같이 여러byte 에 걸쳐 저장된 데이터의 경우 첫번째 byte 의 주소값
**/

int main(int argc, char** argv)
{
	int n = 100;

	// 주소는 주로 16진수로 표현한다
	printf("n = %d n의 주소는 %d, %x, %p \n", n, &n, &n, &n);

	// 주소값 출력시는 %p
	// 변수명 앞에 & 사용하면 변수의 주소값 반환
	// %p 로 출력시 16진수 8자리로 표현 (32bit, 4byte) ※ 16진수 2자리를 1byte 분량에 해당
	printf("n = %d n의 주소는 %d, %x, %p \n", n, &n, &n, &n);

	// 포인터변수, '주소'를 담는 변수.
	int *p; // int 타입 포인터 변수 p
			   // p 는 int 타입 데이터를 가리키는 주소를 담는다.

	p = &n;   // int변수 n 의 주소를 포인터 p 에 대입
	printf("p = %p, &n = %p\n", p, &n);

	// 참조연산자 *
	// 포인터를 사용해서 담고 있는 주소값을 찾아가 그 주소 안의 '값' 을 꺼내는 것. (참조)
	printf("*p = %d\n", *p);

	int *p2;  // int 타입 포인터 p2 선언
	p2 = p;
	printf("p2 = %p, p = %p, &n = %p\n", p2, p, &n);

	printf("*p2 = %d, *p = %d, n = %d\n", *p2, *p, n);

	// 포인터변수에 직접 숫자값 대입 (위험)
	*p = 500;   // p가 가리키는 주소 (int) 500 을 대입..
	printf("*p2 = %d, *p = %d, n = %d\n", *p2, *p, n);

	//p = 100;  // 위험
	//printf("*p = %d\n", *p);  // 접근하면 안되는 메모리 영역을 포인터로 접근하려 하면 에러.


	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

29. C_Work > 09_Pointer > 902_ptr_op.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

/** 
	포인터 연산
	명심:
		포인터 -> 주소
		*포인터 -> 그 주소가 가리키는 값
		포인터 타입 -> 그 주소가 가리키는 값의 타입
	
		포인터변수에 +, - 연산을 하는 것은
		결국 주소값을 증감 하는 것인데,
		주소값이 얼마만큼 증감 하느냐는 '포인터 타입' 에 따라 다르다

		ex) int* 포인터 인 경우 가리키는 값의 타입이  int (4byte) 이기 때문에
		      포인터 값에 + 1 연산을 할 경우 주소값이 4증가한다.
**/

int main(int argc, char** argv)
{
	int n = 555;
	int* p = &n;

	printf("n = %d, p = %p, *p = %d \n", n, p, *p);

	// n, p에 각각 +1 연산을 하면?
	printf("n + 1 = %d, p + 1 = %p, *(p + 1) = %d \n", n + 1, p + 1, *(p + 1));	//*(p + 1)은 쓰레기 값 출력

	printf("\n");

	char ch = 'a';
	char* p2 = &ch;

	printf("ch = %d, p2 = %p\n", ch, p2);
	printf("ch + 1 = %d, p2 + 1 = %p\n", ch + 1, p2 + 1);

	printf("\n");

	double d = 3.14;
	double* p3 = &d;
	printf("d = %f, p3 = %p\n", d, p3);
	printf("d + 1 = %f, p3 + 1 = %p\n", d + 1, p3 + 1);
	printf("d + 3 = %f, p3 + 3 = %p\n", d + 3, p3 + 3);


	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

30. C_Work > 09_Pointer > 903_ptr_arr.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

/** 
	포인터와 배열
	 배열의 이름은 포인터다!  포인터 '상수'다!
	 포인터 연산이 적용된다.
	 배열첨자 연산자 []  ← 결국 포인터 연산이다
	 arr[n] ↔ *(arr + n)   ★★★
**/

int main(int argc, char** argv)
{
	int arr[3] = { 10, 20, 30 };

	// 배열 이름은 곧 '주소'다. 포인터다! 포인터처럼 동작한다.
	// arr 타입은? int * 타입
	printf("arr = %p\n", arr);
	printf("*arr = %d\n", *arr);

	// 포인터 연산 ( +, - ) 작동한다
	printf("arr + 1 = %p, *(arr + 1) = %d, arr[1] = %d \n", arr + 1, *(arr + 1), arr[1]);
	printf("arr + 2 = %p, *(arr + 2) = %d, arr[2] = %d \n", arr + 2, *(arr + 2), arr[2]);

	// 주의! 
	// * 참조연산자 우선순위가 일반적인 산술연산자보다 높다.
	printf("*(arr + 1) = %d,  *arr + 1 = %d\n", *(arr + 1), *arr + 1);


	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

31. C_Work > 10_Struct > a01_struct.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

// 구조체
struct point
{
	int x;		// 멤버변수
	int y;		// 멤버변수
};

// persion 구조체
struct person 
{
	char name[20];	// 이름
	int age;				// 나이
	double weight;	// 몸무게
};

int main(int argc, char** argv)
{
	struct point p1;

	// 멤버연산자(.) 사용하여 구조체 멤버 사용
	p1.x = 100;
	p1.y = 200;

	printf("p1.x = %d\n", p1.x);
	printf("p1.y = %d\n", p1.y);


	struct person p2;
	p2.age = 32;
	p2.weight = 54.7;
	strcpy(p2.name, "홍길동");

	printf("이름 : %s, 나이 : %d, 몸무게 : %.1f\n", p2.name, p2.age, p2.weight);

	// 구조체 선언과 동시에 초기화
	struct person p3 = { "아이언맨", 48, 87.663 };
	printf("이름 : %s, 나이 : %d, 몸무게 : %.1f\n", p3.name, p3.age, p3.weight);

	// 구조체 멤버들 0 으로 초기화
	struct person p4 = { 0 };
	printf("이름 : %s, 나이 : %d, 몸무게 : %.1f\n", p4.name, p4.age, p4.weight);


	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

32. C_Work > 10_Struct > a02_struct_ptr.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

// person 구조체
struct person {
	char name[20];  // 이름
	int age;   // 나이
	double weight;   // 몸무게
};

// typedef로 정의된 타입명으로 사용 가능
typedef struct person PS;   // PS 는 타입명!

int main(int argc, char** argv)
{
	PS p1;
	PS p2;
	PS p3 = { "토르", 100, 90.44 };

	// 구조체에 대한 포인터
	PS* ptr = &p3;
	printf("이름 : %s, 나이 : %d, 몸무게 : %.1f\n", p3.name, p3.age, p3.weight);
	printf("이름 : %s, 나이 : %d, 몸무게 : %.1f\n", (*ptr).name, (*ptr).age, (*ptr).weight);
	printf("이름 : %s, 나이 : %d, 몸무게 : %.1f\n", ptr->name, ptr->age, ptr->weight);


	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

 

 

33. C_Work > 10_Struct > a03_struct_size.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#pragma warning(disable:4996)

typedef struct stu 
{
	int a;
	int b;
} S;

typedef struct
{
	char a;	// 1byte
	int b;		// 4byte
} S2;

typedef struct {
	char a;		// 1byte
	short b;		// 2byte
	int c;			// 4byte
	double d;	// 8byte
} S4;

typedef struct {
	char a;		// 1byte
	double d;	// 8byte
	short b;		// 2byte
	int c;			// 4byte
} S5;

typedef struct
{
	char a[4];	// 4byte
	double b;	// 8byte
} S6;

typedef struct
{
	char a;		// 1byte
	double b;	// 8byte
	char c;		// 1byte
} S7;

int main(int argc, char** argv)
{
	printf("sizeof(S) = %d\n", sizeof(S));		// 8byte
	printf("sizeof(S2) = %d\n", sizeof(S2));	// 8byte
	printf("sizeof(S4) = %d\n", sizeof(S4));	// 16byte
	printf("sizeof(S5) = %d\n", sizeof(S5));  // 24byte
	printf("sizeof(S6) = %d\n", sizeof(S6));	// 16byte
	printf("sizeof(S7) = %d\n", sizeof(S7));	// 24byte

	printf("\n");
	S5 arr[10];
	printf("sizeof(arr) = %d\n", sizeof(arr));


	printf("\n아무키나 입력하면 프로그램 종료합니다\n");
	_getch();
	return 0;
} // end main()

'웹_프론트_백엔드 > JAVA프레임윅기반_풀스택' 카테고리의 다른 글

2020.07.10  (0) 2020.07.10
2020.07.09  (0) 2020.07.09
애플리케이션_테스트 시험(제출 코드와 풀이)  (0) 2020.07.07
2020.07.07  (0) 2020.07.07
2020.07.06  (0) 2020.07.06