#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 <iostream>
//using namespace std;
//using namespace A;

int x=200;
namespace B
{
//using std::cout;
//using std::endl;
using namespace std;

inline void foo() //함수를 호출하는 곳에서 바로 실행하게 해줌. 메모리 할당 X,메모리 절약 실행속도 업
// 단점 함수에잇는 내용이 많아지면 
{
/*cout.operator << (10);
cout <<"1" << endl;
cout << 10 << 29 << "aa"<<'X'<<3.14<< endl;

int x;
cin >> x;
cout << x<< endl;
*/
//int x=100;
//cout << ::x << endl;
/*
float f = 3.14;
int x = int(f);

cout << x << endl;
*/
cout<<"XXXXXXXX"<<endl;
cout<<"XXXXXXXX"<<endl;
cout<<"XXXXXXXX"<<endl;
}
}
//태그가 타입으로 승격
//구조체 태그로부터 변수를 바로 선언할수 있다.

struct BOOK
{
int price;
int page;
};

void main()
{
//B::foo();
BOOK *p1 = (BOOK *)malloc(sizeof(BOOK)*10);

free(p1);
}

//함수 오버로딩
//구조체


+ Recent posts