Declaring type of pointers?

前端 未结 10 2068
花落未央
花落未央 2020-12-01 05:20

I just read that we need to give the type of pointers while declaring them in C (or C++) i.e.:

int *point ;

As far as I know, pointers sto

10条回答
  •  一生所求
    2020-12-01 05:39

    So that it can perform arithmetic and other operations. Consider these two examples:

    int* p; /* let the address of the memory location p pointing to be 1000*/
    p++;
    printf("%u",p); /* prints 1004 since it is an integer pointer*/
    
    
    char *p; /* let the address of the memory location p pointing to be 1000*/
    p++;
    printf("%u",p); /* prints 1001 since it is an char pointer*/
    

    I hope this helps you !

提交回复
热议问题