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 |
Can we access RAM? How? Whats the range of access? Similarly What are other hardware we can access?
What is the use of #include in c?
What is an lvalue in c?
what is stack , heap ,code segment,and data segment
Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon
What will the preprocessor do for a program?
#include show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf(" %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }
can we write a program in c for printf and scanf without using header file stdio.h
The difference between printf and fprintf is ?
write a program to gat the digt sum of a number (et. 15= >1+5=6)
What will be the outcome of the following conditional statement if the value of variable s is 10?
when will be evaluated as true/ if(x==x==x) a) x=1; b) x=0; c) x=-1; d) none