Void pointer vs NULL pointer | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 3

Void pointer vs NULL pointer

What is the difference between void pointer and null pointer in C programming?

10th Jan 2019, 2:15 PM
Ashish B
7 ответов
+ 11
'void' is a data type, which means that the memory location the pointer points to has no specific type, however, it can be casted to a data type if required. 'NULL' is not quite a data type, but rather a value. It's a macro that is used to indicate that the pointer currently does not point to a memory location. This also means that a void pointer can be null, and a null pointer can be of type void. Further reference: https://www.quora.com/What-is-difference-between-null-pointer-and-void-pointer-in-C https://stackoverflow.com/questions/4334831/what-is-a-void-pointer-and-what-is-a-null-pointer
10th Jan 2019, 2:40 PM
Shadow - avatar
+ 8
A pointer pointing to null is a null pointer, meaning it doesn't point to anything. A void pointer can point to any address without knowing the type that it is pointing to. A void pointer can point to null in which case the void pointer is a null pointer. Because a void pointer does not know what type it is pointing to you cannot dereference it without explicitly casting it.
10th Jan 2019, 2:40 PM
Dennis - avatar
+ 3
@Shadow , Thank you!!
10th Jan 2019, 3:24 PM
Ashish B
+ 3
@Dennis, Thank you!
10th Jan 2019, 3:25 PM
Ashish B
how do you initialize a pointer as nul?
25th Jan 2019, 6:24 AM
Səăn Çhęstėř Cåbąnťøģ
Səăn Çhęstėř Cåbąnťøģ - avatar
Syntax for null pointer initialization .. Syntax: <data type> *<variable name> = NULL; Example: int *ptr = NULL;                  char *ptr = '\0';
26th Jan 2019, 3:23 AM
Ashish B
Examples of null pointer and void
17th Nov 2020, 8:09 AM
Maneesha Kumary
Maneesha Kumary - avatar