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?



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

Answer / 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

More C Interview Questions

what is a void pointer?

2 Answers  


What is FIFO?

3 Answers  


how can write all 1to 100 prime numbers using for loop,if and break ?

2 Answers   TCS,


what is the maximum limit of row and column of a matrix in c programming. in linux .

4 Answers   NIIT,


write a c/c++ program that takes a 5 digit number and calculates 2 power that number and prints it?

4 Answers  


Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?

0 Answers  


How does selection sort work in c?

0 Answers  


How to reverse a string using a recursive function, with swapping?

5 Answers  


Why the below program throughs error during compilation? #include<stdio.h> #include<conio.h> enum { ZERO, ONE, TWO, }; main() { printf("%d",&TWO); getch(); }

2 Answers  


what is call by value and call by reference

4 Answers  


write a program that finds the factorial of a number using recursion?

13 Answers   Infosys, TATA,


What is an endless loop?

0 Answers  


Categories