Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

why arithmetic operation can’t be performed on a void pointer?

Answer Posted / vadivel t

Hav an example with an int pointer,
assume compiler allocates two bytes for an int.

int *iptr, iArray[3] = {1, 2, 3};
/*say the iArray starting address would be 1000*/
iptr = iArray[0];
/*When u r trying to do iptr++ then it will point to 1002
(two bytes for an int) where element 2 available.
cos compiler knows how many bytes has two increment*/
iptr++;

Now come to void:

void pointer is generic pointer which can be point to any
kind of data types.

void *ptr;

/*When u r trying to do ptr++, since it is void pointer, it
will not know exactly how many bytes has to be incremented.
So that arithmatic operations not possible with void
pointer.*/

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is #include stdio h and #include conio h?

1040


What is pointer in c?

1141


What is the advantage of an array over individual variables?

1187


What is the benefit of using const for declaring constants?

990


What is the benefit of using #define to declare a constant?

1044


What is actual argument?

1005


How can I split up a string into whitespace-separated fields?

1005


What are valid signatures for the Main function?

1170


Explain Function Pointer?

1103


What is boolean in c?

1033


What is variable initialization and why is it important?

1164


Explain the binary height balanced tree?

1124


Explain how can I read and write comma-delimited text?

1114


Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?

1076


What is the purpose of main( ) in c language?

1089