#include<stdio.h>
void main()
{
int i=100;
printf("%d\n",i);
int *pointer = &i;
printf("%p\n",i);
printf("%p",pointer);
}
Output:
100 // 变量i的数值
0000000000000064 // 变量i的地址 - > 100的hex形式, why?
000000000062FE14 // pointer的地址
In the above code, we first initialize the integer variable i
with int i=100
; and print the integer value of i
, which is 100
. Then we created the pointer pointer
that points towards the address of i
.
In the next line, we printed the pointer value of i with the %p format specifier inside the print() function. The pointer value of i is 0000000000000064 because 100 becomes 64 in hexadecimal. After that, we printed the value inside the pointer with the %p format specifier.
对于systemverilog来说,print %p 是 打印packed element的意思。。。