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
Explain which function in c can be used to append a string to another string?
Why is c still so popular?
What is declaration and definition in c?
What is function what are the types of function?
Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?
If errno contains a nonzero number, is there an error?
What is multidimensional arrays
What are global variables and how do you declare them?
I have seen function declarations that look like this
in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above
What is size of union in c?
List some basic data types in c?
write a program to input 10 strings and compare without using strcmp() function. If the character of one string matches with the characters of another string , sort them and make it a single string ??? example:- str1="Aakash" st2="Himanshu" str="Uday" output:- Aakashimanshuday (please post the answer as quickly as possible)
How can I remove the trailing spaces from a string?
What is memory leak in c?