What is the difference between the * and the & operators in c programming?

前端 未结 3 1297
忘了有多久
忘了有多久 2020-12-29 05:48

I am just making sure I understand this concept correctly. With the * operator, I make a new variable, which is allocated a place in memory. So as to not unnecessarily dupli

3条回答
  •  孤独总比滥情好
    2020-12-29 06:26

    Not quite. You're confusing a * appearing in a type-name (used to define a variable), with the * operator.

    int main() {
        int i;    // i is an int
        int *p;   // this is a * in a type-name. It means p is a pointer-to-int
        p = &i;   // use & operator to get a pointer to i, assign that to p.
        *p = 3;   // use * operator to "dereference" p, meaning 3 is assigned to i.
    }
    

提交回复
热议问题