why arithmetic operation can’t be performed on a void pointer?
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 |
Explain how can I avoid the abort, retry, fail messages?
What is methods in c?
1. Write a program to reverse every second word in a given sentence.
What is the function of multilevel pointer in c?
Explain what is a 'locale'?
what do u mean by Direct access files? then can u explain about Direct Access Files?
In a switch statement, what will happen if a break statement is omitted?
write a program for size of a data type without using sizeof() operator?
22 Answers HCL, IBM,
How can I invoke another program from within a C program?
can you change name of main()?how?
Explain Linker and Loader
write a program to find lcm and hcf of two numbers??