본문 바로가기
코딩/C++

포인터

by sonysame 2024. 3. 7.
#include <iostream>
using namespace std;

void printArray1(int array[]) {
	cout << sizeof(array) << endl;
	*array = 100;
}
void printArray2(int* array) {
	cout << sizeof(array) << endl;
	*array = 200;
}
int main() {

	int array[5] = { 9,7,5,3,1 };
	cout << array[0] << " " << array[1] << endl;

	cout << array << endl;
	cout << &(array[0]) << endl;
	cout << *array << endl;
	cout << sizeof(array) << endl; //20


	int* ptr = array;
	cout << ptr << endl;
	cout << *ptr << endl;
	cout << sizeof(ptr) << endl; //8
	printArray1(array); //8
	cout << array[0] << endl; //100
	printArray2(array); //8
	cout << array[0] << endl; //200
	return 0;

}

 

int value = 7;
int* ptr = &value;
cout << ptr << endl;
cout << uintptr_t(ptr - 1) << endl;
cout << uintptr_t(ptr) << endl;

int array[] = { 9,7,5,3,1 };
cout << array[0] << " " << (uintptr_t)&array[0] << endl;
cout << array[0] << " " << (uintptr_t)&array[1] << endl;

'코딩 > C++' 카테고리의 다른 글

동적할당(new, delete)  (0) 2024.03.08
문자열 const char *  (0) 2024.03.08
구조체  (0) 2024.03.06
자료형 별칭(typedef, using)  (0) 2024.03.05
열거형(enum)  (0) 2024.03.05