c - Why does incrementing a void pointer by 1 moves one byte ahead but it's 4 bytes for an integer pointer,8 for double? -


this question has answer here:

in following program,if add 1 void pointer, moves 1 byte ahead.but,quite expected, moves 4 , 8 bytes respectively int , double pointers.why void pointer move 1 byte,just character pointer would?

#include<stdio.h>  int main(void) {          int num=3,*int_ptr=&num;         double sum=3,*double_ptr=&sum;         void *void_ptr1=&num,*void_ptr2=&sum;         printf("%p,%p,%p,%p,%p,%p,%p,%p",void_ptr1,void_ptr1+1,\         void_ptr2,void_ptr2+1,int_ptr,int_ptr+1,double_ptr,double_ptr+1); } 

you can't pointer arithmetic on void pointer (because doesn't make sense). it's compiler has extension allows pointer arithmetic performed on void pointers, , it's implemented this. however, neither standard nor encouraged used.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -