空指针和空指针的区别是什么?(复制)

时间:2022-11-23 13:25:44

Possible Duplicate:
What's the difference between a null pointer and a void pointer?

可能重复:空指针和空指针的区别是什么?

What is the difference between a pointer to void and a NULL pointer in C? Or are they the same?

指向void的指针和C中的空指针有什么区别?还是它们是一样的?

3 个解决方案

#1


13  

In C, there is void, void pointer and NULL pointer.

在C语言中,有void、void指针和NULL指针。

  1. void is absence of type. I.E. a function returning a void type is a function that returns nothing.
  2. 空是没有类型。也就是说,返回void类型的函数是没有返回任何值的函数。
  3. void pointer: is a pointer to a memory location whose type can be anything: a structure, an int, a float, you name it.
  4. 空指针:是指向内存位置的指针,其类型可以是任何类型:结构、int、浮点数,您可以命名它。
  5. A NULL pointer is a pointer to location 0x00, that is, no location. Pointing to nothing.
  6. 空指针是指向位置0x00的指针,即没有位置。指向。

Examples:

例子:

void function:

无效的功能:

void printHello()
{
   printf("Hello");
}

void pointer:

无效的指针:

void *malloc(size_t si)
{
    // malloc is a function that could return a pointer to anything
}

NULL pointer:

空指针:

char *s = NULL;
// s pointer points to nowhere (nothing)

#2


7  

void is a datatype. void* is just a pointer to an undefined type. A void* can be set to any memory location. A NULL pointer is a any pointer which is set to NULL (0).

空白是一种数据类型。void*只是一个指向未定义类型的指针。void*可以设置为任何内存位置。空指针是任何被设置为空(0)的指针。

So yes, they are different, because a void pointer is a datatype, and a NULL pointer refers to any pointer which is set to NULL.

所以,是的,它们是不同的,因为空指针是一个数据类型,空指针是指任何被设置为NULL的指针。

#3


5  

Pointer to void is a pointer to an unspecified type. Ie. Just a pointer. It can still be a valid pointer, but we don't know what it points to (eg. A function might take a void pointer as a parameter, and then interpret the type according to a different parameter)

指向void的指针是指向未指定类型的指针。Ie。只是一个指针。它仍然可以是一个有效的指针,但是我们不知道它指向什么。函数可以将空指针作为参数,然后根据不同的参数解释类型)

NULL is an 'empty' pointer. Not valid, can be used to specify a pointer to nothing / not set. It is a value whilst void is a type.

NULL是一个“空”指针。无效,可用于指定指向无/未设置的指针。它是一个值,而void是一个类型。

#1


13  

In C, there is void, void pointer and NULL pointer.

在C语言中,有void、void指针和NULL指针。

  1. void is absence of type. I.E. a function returning a void type is a function that returns nothing.
  2. 空是没有类型。也就是说,返回void类型的函数是没有返回任何值的函数。
  3. void pointer: is a pointer to a memory location whose type can be anything: a structure, an int, a float, you name it.
  4. 空指针:是指向内存位置的指针,其类型可以是任何类型:结构、int、浮点数,您可以命名它。
  5. A NULL pointer is a pointer to location 0x00, that is, no location. Pointing to nothing.
  6. 空指针是指向位置0x00的指针,即没有位置。指向。

Examples:

例子:

void function:

无效的功能:

void printHello()
{
   printf("Hello");
}

void pointer:

无效的指针:

void *malloc(size_t si)
{
    // malloc is a function that could return a pointer to anything
}

NULL pointer:

空指针:

char *s = NULL;
// s pointer points to nowhere (nothing)

#2


7  

void is a datatype. void* is just a pointer to an undefined type. A void* can be set to any memory location. A NULL pointer is a any pointer which is set to NULL (0).

空白是一种数据类型。void*只是一个指向未定义类型的指针。void*可以设置为任何内存位置。空指针是任何被设置为空(0)的指针。

So yes, they are different, because a void pointer is a datatype, and a NULL pointer refers to any pointer which is set to NULL.

所以,是的,它们是不同的,因为空指针是一个数据类型,空指针是指任何被设置为NULL的指针。

#3


5  

Pointer to void is a pointer to an unspecified type. Ie. Just a pointer. It can still be a valid pointer, but we don't know what it points to (eg. A function might take a void pointer as a parameter, and then interpret the type according to a different parameter)

指向void的指针是指向未指定类型的指针。Ie。只是一个指针。它仍然可以是一个有效的指针,但是我们不知道它指向什么。函数可以将空指针作为参数,然后根据不同的参数解释类型)

NULL is an 'empty' pointer. Not valid, can be used to specify a pointer to nothing / not set. It is a value whilst void is a type.

NULL是一个“空”指针。无效,可用于指定指向无/未设置的指针。它是一个值,而void是一个类型。