일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- struct
- 선형모델
- Linear Regression
- Overloading
- least square
- 맵리듀스
- inheritance
- Nonlinear Model
- 딥러닝
- 지도학습
- Effective C++
- c++
- Class
- 머신러닝
- kubernetes
- virtual function
- call by reference
- 회귀
- Machine learning
- Nonlinear Function
- 최소제곱법
- MapReduce
- member function
- overriding
- 회귀학습
- local minimum
- 비선형 함수
- call by value
- 비선형모델
- regression
- Today
- Total
J's Study log
[C] Pointer 본문
Pointer
Pointer is one of the most important ideas in C.
(You can scroll down if you already have background knowledge about what pointer is)
Pointer, not like the other types, has data of other variable's address.
It makes a big difference of C from the other languages.
A memory is a hardware which physically have memory spaces.
So each unit of memory space have it's own address.
The pointer is used like a mediator, and let us access memory indirectly to the variable.
How to use
int* pointer = NULL; //(type) * (pointer name) = (address value) ;
If the pointer doesn't need to point something yet, just put 'NULL' like the example.
Warnings
If the pointer is not resetted as soon as you declare, it gets the garbage value.
Usually the pointer must be resetted by the address of a variable by using '&' or it might occur very serious problem.
(Exept when you manage the memory)
If the pointer have nothing to point yet, usually people reset the pointer into 'NULL' temporarily.
('NULL' is declared as '0' in <studio.h>)
Be sure that you've corrected the type of pointer same as the type of variable.
Array Pointer
void Func(int arr[], int num){
...
}
'int arr[]' is not actually constructed, it is just a pointer of array which have address of array from the external.
If the array element changes in the function, it is same as changing the original array.
Function Pointer
This simple code is a simple example of function pointer.
#include <stdio.h>
int add(int a, int b) //int type of return, two int type of parameter
{
return a + b;
}
void executer(int (*fp)(int, int))
{
printf("%d\n", fp(10, 20)); //30 : call function by a parameter
}
int main()
{
executer(add); // 1. pass the memory of add() while calling executer()
/*******************
// 2. instead of line15, pass pointer of function while calling executer()
int (*fp)(int, int);
fp = add;
executer(fp);
*******************/
return 0;
}
/*******************************
//form of using pointer function
rt_ty func_n(rt_ty_of_func_p (*func_p_n)(pr_ty_of_func_p1, pr_ty_of_func_p2))
{
}
rt = return, ty = type
func = function, n = name
p = pointer, pr = parameter
/*******************************
'Computer Language > C' 카테고리의 다른 글
[C] Structure Pointer (0) | 2020.02.08 |
---|---|
[C] Integer (0) | 2019.12.01 |
[C] Data Type (0) | 2019.12.01 |
[C] Format specifier (0) | 2019.12.01 |
[C] Operator Priority (0) | 2019.12.01 |