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

Sumit jaiswal said:   1 decade ago
Void pointer does point any data type but null pointer does not point anywhere.

AmolRaje Lendave said:   1 decade ago
Void pointer is a pointer which is used to point any type of variable..
0 is used to indicate that this pointer does't have any address means it is NULL. Thats why first option is correct.

Gowda said:   1 decade ago
( void * ) is a void pointer..means its a pointer with no specific type...Integer zero 0 has various description depending upon the context in which it is used.
Each pointer has its own NULL values.In fact NULL is #defined in stddef.h to zero value.So NULL pointer basically means pointer containing zero or referencing no where...
for example
int main()
{
int *p=NULL;
if(p==0)
printf("hello");
return 0;
}
prints hello
and we have '\0' null char which is basically a value with all bits set zero...These null pointer and null char are for the purpose programmer convinience

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.


Post your comments here:

Your comments will be displayed after verification.