본문 바로가기
Language/C++

[C] pointer 대체 너는 왜이리 높은 산이냐...

by 담백로봇 2022. 10. 7.

C++을 공부하면서 Pointer에 대한 막연한 phobia 가 있는데 이 기회를 빌어 정복해보고자한다.  근데 너무많네..

오랜만에 등판

 

 Point 가 메모리 기반으로 작동되고 일반 interger variable 을 다룰때와 Array 를 다룰때 좀 더 볶잡해지는 경우가 있다.. 일단 Array를 지칭하는 포인터는 여기까지하고... 차근차근 하면서 공부해야겠다. 좀더 알았던 사실들은 Pointer가 Array를 자체를 가르키는 경우 Arr[0]의 주소를 가르키게되고 표현하면 int (*Ptr)[5] 로 선언이 되며 Ptr =&arr 로 이닛이 된다. 

 

#include <iostream>
using namespace std;
int main()
{
    // Pointer to an integer
    int *p;
     
    // Pointer to an array of 5 integers
    int (*ptr)[5];
    int arr[5];
     
    // Points to 0th element of the arr.
    p = arr;
     
    // Points to the whole array arr.
    ptr = &arr;
     
    cout << "p =" << p <<", ptr = "<< ptr<< endl;
    p++;
    ptr++;
    cout << "p =" << p <<", ptr = "<< ptr<< endl;
     
    return 0;
}

 

참고 자료 

1) 기본 포인터 설명

https://www.geeksforgeeks.org/pointers-in-c-and-c-set-1-introduction-arithmetic-and-array/?ref=lbp 

 

Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array) - GeeksforGeeks

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

www.geeksforgeeks.org

2) 포인터 퀴즈

https://www.geeksforgeeks.org/c-language-2-gq/pointers-gq/

 

Pointer Basics in C - GeeksQuiz

Quiz or Mock test on pointers in C programming language. The quiz contains multiple choice and output questions for GATE and technical interview preparation

www.geeksforgeeks.org

3) Pointer to Array

https://www.geeksforgeeks.org/pointer-array-array-pointer/

 

Pointer to an Array | Array Pointer - GeeksforGeeks

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

www.geeksforgeeks.org

 

댓글