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 are types of preprocessor in c?

1066


What does #pragma once mean?

1162


How can variables be characterized?

2184


FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)} a.error b. c. d.

1743


Write a code on reverse string and its complexity.

1028


How can you find out how much memory is available?

1065


What is a substring in c?

1032


What is a constant and types of constants in c?

1114


When should volatile modifier be used?

1010


If I have a char * variable pointing to the name of a function ..

1165


How many types of sorting are there in c?

1051


Explain what are bus errors, memory faults, and core dumps?

1271


Why is sprintf unsafe?

1068


Write a programme using structure that create a record of students. The user allow to add a record and delete a record and also show the records in ascending order.

2089


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3683