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
What is #include stdio h and #include conio h?
What is pointer in c?
What is the advantage of an array over individual variables?
What is the benefit of using const for declaring constants?
What is the benefit of using #define to declare a constant?
What is actual argument?
How can I split up a string into whitespace-separated fields?
What are valid signatures for the Main function?
Explain Function Pointer?
What is boolean in c?
What is variable initialization and why is it important?
Explain the binary height balanced tree?
Explain how can I read and write comma-delimited text?
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
What is the purpose of main( ) in c language?