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 2 of 13.

Anshul said:   1 decade ago
void *p;
/* It is a void type pointer i.e it can point too any object either int,float,etc.It means "void *p;" has certain address in the memory let take 12345.But if point to (void*)0 now it's address is 0 it means it is pointing to NULL in C.What it suggest to us is void *p is generic pointer point to any data type here (void*)0 is null pointer i.e it always point to NULL. */
summary..
void *ptr;// Address:12345
void *ptr=(void*)0; //Address:0

Dileep Gidwani said:   1 decade ago
As we know pointer doesn't have any return type, we write the keywords like int, float or char before * when we create a pointer. These keyword show that which type of value's or variable's address pointer will keep. And here we can see that we have used void before * that means pointer will not point any memory location. And we know that pointer which doesn't point any memory location is called null pointer.

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.

MANISH said:   10 years ago
#include<stdio.h>
void print(int*,int*,int*,int*,int*);
int main()
{
int arr[]={97,98,99,100,101,102,103,104};
int *ptr=arr+1;

print(++ptr,ptr--,ptr,ptr++,++ptr);
return 0;
}
void print(int *a,int *b,int *c,int *d,int *e)
{
printf("%d %d %d %d %d",*a,*b,*c,*d,*e);
}


Please help my in understanding the output of the above. Each step with clear description.

Kranthi said:   1 decade ago
The main difference between NULL pointer and Void pointer is, Null pointer doesn't represent any memory location.Its value is 0. But void pointer can represents to memory location of its own type.

In the example (Void*)0(zero). it means a pointer type void represents to the location of zero.so its NULL(as mentioned 0 in the example) so syntax for the NULL pointer can be used as (Void*)0

Preet said:   1 decade ago
The 'void pointer' is pointer that contain address but the datatype of the value stored at that address is not known.

It can be cast to any data type while Null pointer is a pointer that always refers to the 0th location of memory. This location is always reserved for Null and any other value can't be stored in that location.

That's why (void*)0 is NULL pointer.

Kintali Prasanti said:   1 decade ago
Hi all,

As of I know this is the explanation.

Void pointer is a type of pointer which can store any type of value and null pointer is a pointer which does not point to anything. So here it is mentioned as "(void*)0" means we are declaring a void pointer holding 0 as its value which is an indirect representation of null pointer.

Thanks,

Vikram.s said:   1 decade ago
You can use the 0(zero) at the NULL, but in the program you may have the value 0(zero) which is required for the program, to differentiate that in <stdio.h> or <stddef.h> they have predefined this NULL as macro with,

#define NULL (void*)0.

Just to avoid the confusions of the value 0(zero), is value zero or NULL pointer.

Vinayak said:   1 decade ago
I think, since the representation of void with no parameter is (void).if we represent it in the form of (void*)0=>a pointer pointing to a location which is already been deallocated by using free() deallocation function.so it points to a location which has nothing i.e null.Hence it is rightly called as null pointer.

Sree said:   1 decade ago
The void data type has no values.

Example:

int a=10; //right
void b=20;//wrong

pointer
a[address of 10]--------->10

pointer
b[address]---------> NULL (no value,no address so null)

So void is a representation of NULL.

Note: void *b; //right (no value, but we can store address)


Post your comments here:

Your comments will be displayed after verification.