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 malloc() function?

0 Answers  


write a C program : To find out the number of identical words in two files . the file name should be taken as command line argument .

1 Answers   Subex,


define function

4 Answers   Assurgent, Sonata,


Explain what does the function toupper() do?

0 Answers  


Given an array of length N containing integers between 1 and N, determine if it contains any duplicates.

3 Answers   SilverKey,






to find the program of matrix multiplication using arrays

6 Answers   Bhel,


Explain how can I remove the trailing spaces from a string?

0 Answers  


what is data structure

5 Answers   Maveric, TCS,


C program to perform stack operation using singly linked list

3 Answers  


how to display 2-D array elements in spiral

2 Answers  


What is #include cctype?

0 Answers  


name the language for writing c compiler?

3 Answers   Microsoft,


Categories