#include <iostream>

//1.
/* new , delete
#include <malloc.h>

using namespace std;

void main()
{
int *p3 = new int;

int *p1 = (int *)malloc(sizeof(int)*10); 
int *p2 = new int[10];
delete p3;
delete [] p2;
free(p1);
int *p1 = (int *)malloc(sizeof(int)*10); //일반화 프로그래밍 !! ->void *  
free(p1);
}*/


//2.
/*

//참조 변수(REF)   & 참조형 변수
//변수에 대한 또다른이름 --> 별명--> 알리아스
using namespace std;
//call by value
void SWAP(int x, int y)
{
int temp;
temp = x;
x = y;
y = temp;
}
//c언어 call by ref
void SWAP(int *x, int* y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
// 레퍼런스를 이용한 call by ref
void SWAP(int & x, int & y)
{
int temp = x;
x = y;
y = temp;
}

void main()
{
int x = 10;
int y = 20;
cout << x << "  " << y << endl;
SWAP(&x,&y);
cout << x << "  " << y << endl;
cout << x << "  " << y << endl;
SWAP(x,y);
cout << x << "  " << y << endl;

cout << x << "  " << y << endl;
SWAP(x,y);
cout << x << "  " << y << endl;

int LEE_TAE_WON = 100;
//참조형 변수는 선언과 동시에 참조가 되어야 한다.
int & p = LEE_TAE_WON;
cout << LEE_TAE_WON << endl;
cout <<  p << endl;

}
*/
/*
//3.함수 오버로딩 ( 다중정의 )
//정의 : 같은 이름의 함수가 매개변수의 갯수와 타입에 따라서 
//   서로 다른 함수로 인식 하는 것

using namespace std;
//함수 원형 선언
void print();
void print(int);
void print(int , int);

void main()
{
print();
}

void print()
{
cout << "printf()" << endl;
}
void print(int x)
{
cout <<"printf(int x)" << endl;
}
void print(int x, int y)
{
cout <<"printf(int x,int y)" << endl;
}
*/

/*
//4,디폴트 파라미터 

using namespace std;

void foo(int Snum = 100, int age =20, char *name = "홍길동") 
{
cout <<"학번은"<<Snum<< "나이는" << age<< "살"<< " 이름은 "<<  name << "입니다."<< endl;
}

void main()
{
foo();
}
*/
/*
//함수 오버로딩은 같은 로직의 함수가 매개변수의 타입에 따라 구현될경우사용
//
int plus(int x = 0, int y = 0)
{
return x+y;
}
double plus(float x = 0, float y = 0)
{
return double(x+y);
}
using namespace std;

void main()
{
cout << plus() << endl;
}
*/
/*
#include <malloc.h>
 //c++ 동적 메모리 사용!!
using namespace std;

void main()
{

int *p = (int *)malloc(sizeof(int)*10);

//재할당
p = (int *)realloc(p , _msize(p)*2);
cout <<  _msize(p) << endl;
free(p);

int *p2 = new int[10];
// int *p3 = &(*p2);
p2 = new int[_msize(p2)/sizeof(int)*2];
// memcpy(p3,p2,_msize(p2));
// p3 * 2;

cout << _msize(p2) << endl;
delete [] p2;
}
*/

using namespace std;

int *dong(int size_t=1, bool check_zero=0,int *q=0)
{
int *temp = new int[size_t];
if(check_zero)
{
memset(temp,0,_msize(temp));
}
if(q)
{
memcpy(temp,q,sizeof(int)*size_t);
delete [] q;
}
return temp;
}
void main()
{
int *p = new int[10];
p[0] = 5;
p[2] = 3;
p = dong(3,1,p);
cout << p[1] << endl;
cout << _msize(p) << endl;
}


#include <stdio.h>
void swap(int *a, int *b);
void main()
{
int a;
int b;

printf(" a 를 입력하시오 : ");
scanf_s("%d",&a);

printf(" b 를 입력하시오 : ");
scanf_s("%d",&b);

swap(&a,&b);

printf("a:,%d\n",a);
printf("b:,%d\n",b);

}

void swap(int *a, int *b)
{
int temp=*a;
*a = *b;
*b=temp;
}




'Programing > C' 카테고리의 다른 글

c 윤달 구하기, 윤달계산  (0) 2016.11.30
#undef , 전처리문  (0) 2016.11.30
짝수 합 홀수 합 구하기  (0) 2016.11.30
C언어 루트값 구하기  (0) 2016.11.30
C 완전수 구하기  (0) 2016.11.30

+ Recent posts