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 types of preprocessor in c?
What does #pragma once mean?
How can variables be characterized?
FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)} a.error b. c. d.
Write a code on reverse string and its complexity.
How can you find out how much memory is available?
What is a substring in c?
What is a constant and types of constants in c?
When should volatile modifier be used?
If I have a char * variable pointing to the name of a function ..
How many types of sorting are there in c?
Explain what are bus errors, memory faults, and core dumps?
Why is sprintf unsafe?
Write a programme using structure that create a record of students. The user allow to add a record and delete a record and also show the records in ascending order.
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.