LectureNote_03
LectureNote_03
(Lecture Note 3)
2025. 3. 11
#include <stdio.h>
void main()
{
What happens exactly ?
int a[] = {1, 2, 3, 4, 5};
int *p; Draw the procedure for this !
p = a;
printf(“%d %d %d\n”, a[1], a[2], a[3]);
printf(“%d %d %d\n”, p[1], p[2], p[3]);
p[1] = 7;
p[2] = 8;
} p[3] = 9;
a b (copy)
#include <stdio.h>
void swap(int x, int y)
void swap(int x, int y); {
int temp;
void main()
{ temp = x;
int a = 100, b = 200; x = y;
printf(“a = %d, b = %d\n”, a, b); y = temp;
swap(a, b); }
printf(“a = %d, b = %d\n”, a, b);
} [ swap function ]
#include <stdio.h>
void swap(int *x, int *y)
void swap(int x, int y); {
int temp;
void main()
{ temp = x;
int a = 100, b = 200; x = y;
printf(“a = %d, b = %d\n”, a, b); y = temp;
swap( , ); } Modify it !
printf(“a = %d, b = %d\n”, a, b);
} [ swap function ]
#include <stdio.h>
Consider following sentences :
int function_A(int N)
{ 1) fptr = function_A
int a;
for(a = 0; N > 0; N--) 2) printf(“%d\n”, function_A(100));
a += N; printf(“%d\n”, fptr(100));
return a;
}
This will be frequently employed with
What does this function do ?
void pointer
Function pointer : int (*fptr) (int);
Make a generalized version
※ Bracket is required
※ Usage : type (pointer) (type)
void *vptr;
int **q;
#include <stdio.h>
3 p ?
void main()
{ 4 q ?
int j = 9;
int *p = &j;
int **q = &p;
7 9 j ?
*p = 10; 8 39 ?
**q = 9;
}
S[0][0] S[0][1] S[0][2] S[0][3] S[0][4] S[1][0] … S[2][0] S[2][1] S[2][2] S[2][3] S[2][4]
… 1 2 3 4 5 6 7 8 9 0 …
* Name “array” indicates three (int types) pointers in the memory space !
Where do array+1 and array+2 indicate in the memory ?
#include <stdio.h>
void main()
{ Fill out the blank only using a pointer !
int a[2][2] = { {1,2}, {3,4} };
start = ;
end = ;
return avg;
}
Deep Computer Vision Lab.
15
Summary
Content
Basic concept of advanced operations for pointers
• Relationship between array and pointer
• Pointer and function / void pointer (casting)
• Function pointer / pointer of pointer
※ Remember the definition of “pointer of pointer”