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 a void pointer?
What is FIFO?
how can write all 1to 100 prime numbers using for loop,if and break ?
what is the maximum limit of row and column of a matrix in c programming. in linux .
write a c/c++ program that takes a 5 digit number and calculates 2 power that number and prints it?
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?
How does selection sort work in c?
How to reverse a string using a recursive function, with swapping?
Why the below program throughs error during compilation? #include<stdio.h> #include<conio.h> enum { ZERO, ONE, TWO, }; main() { printf("%d",&TWO); getch(); }
what is call by value and call by reference
write a program that finds the factorial of a number using recursion?
What is an endless loop?