What is the difference between null pointer and void pointer
Answer Posted / abi
Yes there are differences between a null pointer and a void
pointer. As you know that a pointer holds the memory address
of any variable . So we can say for a null pointer that :
- A null pointer can be of any primitive type(e.g - int *
,char * etc)
-However a null pointer does not point to any memory
location , i.e. it does not contain a reference of any
variable/value. Hence we may state that it has a NULL as its
value making it a null pointer.
Where as in case of a void pointer we can say :
- void pointer is always of type void *
- Mainly such pointers are used for dynamic memory
allocations (using malloc(), calloc() and realloc()
functions) , where memory block reserved is pointer to by a
void pointer and as the pointer value is returned it has to
be explicitly type casted to a particular desired type.
for e.g
int * ptr;
ptr=(int *) malloc(sizeof(int));
[ Here malloc () returns a pointer of void * type(i.e a void
pointer) which is type casted to int * as per our requirement ]
Is This Answer Correct ? | 15 Yes | 1 No |
Post New Answer View All Answers
Can you please explain the scope of static variables?
What is zero based addressing?
Explain modulus operator. What are the restrictions of a modulus operator?
Do pointers need to be initialized?
Why is c still so popular?
Differentiate between Macro and ordinary definition.
In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]
What is the use of sizeof () in c?
Explain how do you print only part of a string?
What is the scope of an external variable in c?
Explain the difference between ++u and u++?
What is the most efficient way to count the number of bits which are set in an integer?
What are the advantages and disadvantages of a heap?
How the c program is executed?
What is the use of a static variable in c?