- Syntax
typename * pointer_name ;
int *p;
// p คือพอร์ยเตอร์สำหรับตัวแปรอะไรก็ได้ที่เป็นชนิด intfloat *pf ;
// pf คือพอร์ยเตอร์สำหรับตัวแปรที่เป็นชนิด floatchar *str ;
// str คือพอร์ยเตอร์สำหรับตัวแปรชนิด char- การเข้าถึงข้อมูลโดยเรียกชื่อตัวแปร เรียกว่า : direct access
- การเข้าถึงข้อมูลโดยการดีรีเฟอร์เรนซ์พอร์ยเตอร์เรียกว่า : indirect access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) | |
{ | |
int a = 5; | |
char ch = 'k'; | |
printf("%d\n",a); | |
printf("%c\n",ch); | |
int *pa = &a; | |
char *pch = &ch; | |
printf("%d , %d\n",*pa,a); | |
printf("%d , %d",*pch, ch); | |
return 0; | |
} |