c 指针打印变量
Any type of pointer variable takes the same memory bytes in the memory, because they are used to store the memory addresses on other type of variables.
任何类型的指针变量都在内存中占用相同的内存字节,因为它们用于在其他类型的变量上存储内存地址。
Let’s take an example - There are two pointers 1) integer pointer and 2) char pointer, integer pointer will take 4 bytes (in case of, 32 bits compiler) and will store the address of integer variables only. char pointer will also take 4 bytes but it will store the address of only char variable.
让我们举个例子 -有两个指针1) 整数指针和2) char指针 ,整数指针将占用4个字节(对于32位编译器而言),并将仅存储整数变量的地址。 char指针也将占用4个字节,但它将仅存储char变量的地址。
In this C program, we are testing the same by printing the size of different types of pointers.
在此C程序中,我们通过打印不同类型的指针的大小来进行测试。
C程序打印不同类型指针的大小 (C program to print sizes of different type of pointers )
</ s> </ s> </ s>/*C program to print size of different types of pointer variables.*/
#include <stdio.h>
int main()
{
printf("\nsize of char pointer: %d" ,sizeof(char*));
printf("\nsize of int pointer: %d" ,sizeof(int*));
printf("\nsize of float pointer: %d" ,sizeof(float*));
printf("\nsize of long int pointer: %d" ,sizeof(long int*));
printf("\nsize of double pointer: %d\n" ,sizeof(double*));
return 0;
}
Output
输出量
size of char pointer: 4
size of int pointer: 4
size of float pointer: 4
size of long int pointer: 4
size of double pointer: 4
~~~~ Output depends on the system architecture,
~~~~ but each type of pointer will take same memory space ~~~
~~~~输出取决于系统架构,
~~~~但是每种类型的指针都会占用相同的内存空间~~~
翻译自: https://www.includehelp.com/c-programs/c-pointer-program-to-print-size-of-different-types-of-pointer-variables.aspx
c 指针打印变量