C Programming - Pointers - Discussion
Discussion Forum : Pointers - General Questions (Q.No. 1)
1.
What is (void*)0?
Discussion:
124 comments Page 6 of 13.
DNY said:
1 decade ago
Dear friend (void *) is very imp pointer that c allow us to keep any type data under it.
I simply mean that if we want store adds of int I=10;
Into any pointer we required int *.
But when we use void pointer mean it can hold adds of any type of variable.
Int I=10;
Void * vptr=&I;
Now ans of above question:
When we assign 0 value to any pointer simply it mean it pointing to 0000 location of memory.
It mean it is not pointing to any variable so it is NULL pointer.
I simply mean that if we want store adds of int I=10;
Into any pointer we required int *.
But when we use void pointer mean it can hold adds of any type of variable.
Int I=10;
Void * vptr=&I;
Now ans of above question:
When we assign 0 value to any pointer simply it mean it pointing to 0000 location of memory.
It mean it is not pointing to any variable so it is NULL pointer.
Harsh said:
1 decade ago
NULL pointer can be portably expressed as the integer value 0 converted implicitly or explicitly to the type void*.
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
/* 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
Lohith said:
1 decade ago
void it self states empty or 0.
i.e mean nothing.
For void no memory location is allocated.
i.e mean nothing.
For void no memory location is allocated.
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.
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.
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)
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)
Anurag said:
1 decade ago
#include<stdio.h>
main()
{
int num=258;
int *p=#
printf("%d %d \n",*((char*)p),*((char*)p+1));
}
Please give the answer with suitable reason?
main()
{
int num=258;
int *p=#
printf("%d %d \n",*((char*)p),*((char*)p+1));
}
Please give the answer with suitable reason?
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.
Hafeezkhan said:
1 decade ago
1st void function_name (void).
1st void indicate function type is null.
1st void indicate function type is null.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers