What's the difference between a pointer, and a pointer variable?

前端 未结 6 1558
执笔经年
执笔经年 2021-02-04 10:50

I know this is very basic but it is little bit confusing to me.
I\'ve read:

a pointer is nothing more than an address

6条回答
  •  孤独总比滥情好
    2021-02-04 11:32

    The token p is a pointer variable, that points to a variable i. We can simply call it a pointer.

    A declaration:

    int* p;
    int i;
    p = &i; 
    

    declares p as the identifier of an int type object. This is usually stated more succinctly as 'p is a pointer to i'. p can be used to refer int variable i after expression p = &i. To access the value of variable i using pointer p you can use the dereference operator * (e.g. *p). And i = 10; equivalent to *p = 10;.

    Also, notice in expression p = &i; to read the address of i I used & ampersand operator also called Address of operand.

    A pointer is just a logical address (an identifier by which a variable can be referenced). The C standard does not define what a pointer is internally and how it works internally.

    You would like to read: What exactly is a C pointer if not a memory address?
    Additionally, read this: to Understand the purpose of pointers.

提交回复
热议问题