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 |
What is malloc() function?
write a C program : To find out the number of identical words in two files . the file name should be taken as command line argument .
define function
Explain what does the function toupper() do?
Given an array of length N containing integers between 1 and N, determine if it contains any duplicates.
to find the program of matrix multiplication using arrays
Explain how can I remove the trailing spaces from a string?
what is data structure
C program to perform stack operation using singly linked list
how to display 2-D array elements in spiral
What is #include cctype?
name the language for writing c compiler?