why arithmetic operation can’t be performed on a void pointer?



why arithmetic operation can’t be performed on a void pointer?..

Answer / 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

More C Interview Questions

Can we access RAM? How? Whats the range of access? Similarly What are other hardware we can access?

1 Answers  


What is the use of #include in c?

0 Answers  


What is an lvalue in c?

0 Answers  


what is stack , heap ,code segment,and data segment

0 Answers  


Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon

0 Answers  


What will the preprocessor do for a program?

0 Answers   Aspire, Infogain,


#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); }

0 Answers   Wilco,


can we write a program in c for printf and scanf without using header file stdio.h

1 Answers  


The difference between printf and fprintf is ?

0 Answers   Baan Infotech,


write a program to gat the digt sum of a number (et. 15= >1+5=6)

2 Answers  


What will be the outcome of the following conditional statement if the value of variable s is 10?

0 Answers  


when will be evaluated as true/ if(x==x==x) a) x=1; b) x=0; c) x=-1; d) none

7 Answers   HCL,


Categories