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 are examples of structures?
What are keywords in c with examples?
What are the types of operators in c?
What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.
In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.
What does != Mean in c?
What is c standard library?
How can I get random integers in a certain range?
Explain how do you print an address?
List the difference between a "copy constructor" and a "assignment operator"?
A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream
Write a code to determine the total number of stops an elevator would take to serve N number of people.
Q.1 write a program to create binary tree 1 to 16 numbers? Q.2 write a program to creat a binary search tree for the member that is given by user?
Here is a neat trick for checking whether two strings are equal
What is meant by int main ()?