C/C++

· Language/C++
Declaring a Pointer as Const -1 int num = 20; const int* ptr = # 포인터 ptr은 num의 주소 값을 가리킨다. 그 앞에 const를 붙이면 포인터를 통해서 변수의 값을 수정할 수 없다. *ptr = 30; // compile error! 하지만 num 변수 자체의 값을 수정할 때는 에러가 나지 않는다. num = 30; // OK Declaring a Pointer as Const -2 int num1 = 20; int num2 = 30; int* const ptr = &num1; 요번에는 포인터 앞에 ptr을 const를 붙였다. -> ptr의 값은 수정할 수 없다. -> 다른 변수를 가리키도록 ptr 값을 수정할 수 없다. ptr = &num..
· Language/C++
Structure variable struct book{ char title[50]; char autor[50]; char subject[100]; int book_id; }; struct book book1; book은 구조체의 type 이름이며, book1은 book 구조체 타입을 가지는 변수이다. book1.book_id = 0; book의 구조체 타입을 가진 book1의 member에 접근하고 싶을 때 member access operation "."을 붙여서 member name을 선택한다. typedef typedef unsigned int MyType; typedef을 사용함으로써 새로운 이름을 가진 타입을 줄 수 있다. typedef and struct struct point { int x..
행복한쿼콰
'C/C++' 태그의 글 목록