Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

การใช้ %p ใน printf ในภาษา C

%p เป็น Format Specifier สำหรับพิมพ์ค่าพอยน์เตอร์ (ที่อยู่หน่วยความจำ)

ตัวอย่าง

#include <stdio.h>

int main() {
    int x = 50;
    int *ptr = &x;
    printf("The address is: %p, the value is %d", ptr, *ptr);
    return 0;
}

ผลลัพธ์

The address is: 000000000022FE44, the value is 50