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

Vijay 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)

Kutti said:   1 decade ago
0 used to any place null value. Then 0 used no any value. So (void*) 0 is null pointer. Example 1*0=0. This mean no value.

Hafeezkhan said:   1 decade ago
1st void function_name (void).
1st void indicate function type is null.

Debopam Pal said:   1 decade ago
Actually, when a data type is written within first bracket followed by a value then that value is converted to that data type, is called type casting. Likewise, when we use a pointer of any type within a first bracket followed by a value, then that pointer automatically points to that value. So, here both the data type (i.e pointer of any data type and the data type of the value) must be same. But when we use void type pointer that time we can use this syntax for any value, i.e (void*)0 -> a void type pointer points to 0 or NULL, i,e Null Pointer.

Anurag said:   1 decade ago
#include<stdio.h>
main()
{
int num=258;
int *p=&num;
printf("%d %d \n",*((char*)p),*((char*)p+1));
}
Please give the answer with suitable reason?

Vishal Dalawai said:   1 decade ago
@Anurag.

Output : 2 1

The output of above program depends on the architecture(Little Endian/Big Endian).Intel processor uses Little Endian architecture.

Little Endian: LSB bits are stored in Lower memory locations & MSB bits are stored in Higher memory locations.

The binary equivalent of no 258(32 bit compiler)
(MSB) (LSB)
00000000 00000000 00000001 00000010

Suppose,the value 'num' stored in memory location 0x1000.Then the value 'num' stored in memory as below.

Address : 0x1000 0x1001 0x1002 0x1003
value : 00000010 00000001 00000000 00000000

Now,the integer pointer contains base address(0x1000).

The code '(char*)p' typecast the integer pointer to character pointer & points to address 0x1000 & *((char*)p) gives the value 2,which is 00000010.

The code '((char*)p+1)' typecast the integer pointer to character pointer & incrementing by 1.Now Pointer,pointing to memory location
0x1001 & *((char*)p+1) gives the value 1,which is 00000001

Note:Whenever pointer is increment/decrement,it is always increment/decrement of its data type size(char = 1Byte,Int = 4Bytes)

Georgekutty said:   1 decade ago
The actually thing is void means empty data type.

It pointers to variable but compiler don't know the type of data pointer points to. But it stores the address of it.

If it point to zero or NULL it is NULL pointer.

Lohith said:   1 decade ago
void it self states empty or 0.
i.e mean nothing.
For void no memory location is allocated.

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

Harsh said:   1 decade ago
NULL pointer can be portably expressed as the integer value 0 converted implicitly or explicitly to the type void*.


Post your comments here:

Your comments will be displayed after verification.