Programming/C(5)
-
포인터
포인터란:변수를 저장하는 메모리의 주소값 1) 주소연산자(&):포인터를 구해준다. 2) 참조연산자(*):포인터가 가리키는 기억공간 사용한다. 주소 연산자12345int in;printf("in의 포인터: %u",&in); //출력 결과//in의 포인터: 1245048cs 참조 연산자123456int in;*&in = 100;printf("변수 in에 저장된 값: %d", in); //출력 결과//변수 in에 저장된 값: 100cs **값 대입하기** 123int a=10, b=20;b = *&a; //혹은 *&b = *&a//두 가지 방법 모두 가능cs **주소값을 저장하려면** 1234int a;int *ap; //ap는 int형 변수의 시작주소값만 저장할 있다는 뜻ap = &a; //주소값 저장됨 *..
2017.02.18 -
선택정렬, 버블정렬
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556#include#define size 6 void selectSort(int arr[]) { int i, j, index, temp, cnt =0; for (i = 0; i
2017.02.13 -
if~else, switch문
12345678910111213141516#include//짝수를 구하는 함수 bool odd(int n) { return n%2; //true와 1은 동일} int main() { int n; scanf("%d",&n); if (odd(n)) { printf("입력받은 n은 홀수입니다.\n"); }else { printf("입력받은 n은 짝수입니다.\n"); }}cs if~else, switch문 1234567891011121314151617181920212223242526272829303132333435363738394041#include int compare(int a, int b, int c) { int temp; if (a > b) { temp = a; }else { temp = b; } if ..
2017.02.13 -
데이터타입(기본, 파생형)
12345678910111213141516171819202122232425262728293031323334#include int main() { char a=128; //char는 문자/숫자 모두 가질 수 있다. printf("char a : %d \n", a); printf("char a : %c \n", a); unsigned char b = 255; printf("unsigned char b : %d \n", b); char c = 'a'; printf("char c : %c, %d \n", c, c); short int d = 32768; //16비트 printf("short int d : %d \n", d); short e = 32768; //int 생략 가능 printf("short e : %..
2017.02.13 -
시작하기
**시작하기**개발툴은 비주얼 스튜디오 이용.비주얼 스튜디오는 C언어로 된 파일을 기계가 이해할 수 있도록비트(0, 1)로 된 기계어로 변환(컴파일)해준다. **배운 것**1) printf()로 숫자 출력하는 법2) scanf()는 키보드로 값 입력 받을 수 있게해줌 12345678910111213141516#include //Standard Input/Output Header의 약자//자바의 import와 비슷한 개념//printf()를 포함함 int main(){ printf("내 나이는: "); printf("%d", 26); //기본 문자열 인식하므로 변환해줘야 printf("\n"); //띄어쓰기 int num1, num2; printf("아버지, 어머니 나이 입력하세요\n"); scanf("%..
2016.10.29