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
Where local variables are stored in c?
what are the advantages of a macro over a function?
Explain the use of keyword 'register' with respect to variables.
How to throw some light on the b tree?
Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.
write a program to reverse a every alternetive words in a string in a place. EX: Input is "this is the line of text" Output should be "shit is eht line fo text" Please any one tell me code for that.
Explain what does the function toupper() do?
What is the use of printf() and scanf() functions?
Write a program for Overriding.
How can I recover the file name given an open stream?
What is the purpose of & in scanf?
Explain what are its uses in c programming?
what is ur strangth & weekness
What is #line in c?
Is null always equal to 0(zero)?