C Programming - Pointers - Discussion

Discussion Forum : Pointers - General Questions (Q.No. 1)
1.
What is (void*)0?
Representation of NULL pointer
Representation of void pointer
Error
None of above
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
124 comments Page 9 of 13.

Anitha said:   1 decade ago
void is a return type (void *) is represented by NULL pointer.

Rahul chaudhary said:   1 decade ago
int i=1,j;

j=sizeof(++i + j++);
printf("%d%d",i,j);

What will be the output of this program a getting confuse please explain it.

Rajput Naresh said:   1 decade ago
@Rahul.

Expression within sizeof() not solved.

Gowthami said:   1 decade ago
Void data type does not have values.

Santhu84 said:   1 decade ago
#ifndef NULL
# define NULL ((void *) 0)
#endif

Then you can use NULL in different functions.

Nisha sahu said:   1 decade ago
In function we are using void as return type, in pointer why we are not using void as return type instead of void*.

Spandya said:   1 decade ago
void pointer can store address of any data type value.

Declaration of Void Pointer :

void * pointer_name
Void Pointer Example :

void *ptr; // ptr is declared as Void pointer.

char cnum;
int inum;
float fnum;

ptr = &cnum; // ptr has address of character data.
ptr = &inum; // ptr has address of integer data.
ptr = &fnum; // ptr has address of float data.

Explanation :

void *ptr;

Void pointer declaration is shown above.
We have declared 3 variables of integer, character and float type.
When we assign address of integer to the void pointer, pointer will become Integer Pointer.
When we assign address of Character Data type to void pointer it will become Character Pointer.
Similarly we can assign address of any data type to the void pointer.
It is capable of storing address of any data type.

Arihant Jain said:   1 decade ago
Null pointer is a special reserved value of a pointer. A pointer of any type has such a reserved value. Formally, each specific pointer type (int *, char * etc.) has its own dedicated null-pointer value. Conceptually, when a pointer has that null value it is not pointing anywhere.

Void pointer is a specific pointer type - void * - a pointer that points to some data location in storage, which doesn't have any specific type.

So, null pointer is a value, while void pointer is a type. These concepts are totally different and non-comparable.

Tejashwini said:   1 decade ago
Null pointers are the pointers which is pointing to nothing.
For example it can be represented as.

1) int *ptr=(char*)0;
2) char *ptr='\0';
or
3) int *ptr=null..

It can be for any data type.

When it comes to void pointers. The pointer will not point to any data and therefore cannot be dereferenced. It is still a pointer though, to use it you just have to cast it to another kind of pointer first.

Venu said:   1 decade ago
Void pointer is a pointer which can point to any data type. It's only purpose is to achieve compatibility between pointers which point to different data types.

Null pointer points to nowhere in the memory.

This problem might confuse because of the use of (void*) which is type casting to a void pointer but since the value after (void*) is zero so it leads to a null pointer.

Try this example:

#include<stdio.h>
void main()
{
int *p;
p=(void*)0;//replace 0 by any value, else part will be executed
if(p=='\0')
printf("null pointer\n");
else
printf("not a null pointer");
}


Post your comments here:

Your comments will be displayed after verification.