When changing the value of a variable in C, is a new primitive created or is the current primitive mutated?

后端 未结 2 1438
醉梦人生
醉梦人生 2020-12-11 21:01

I know that \'mutable\' and \'immutable\' are terms that should be used to describe the ability for objects to change value in object oriented languages such as Java and Obj

2条回答
  •  没有蜡笔的小新
    2020-12-11 21:42

    It should be the current primitive modified. I tested using a simple code here, and it refers to the same address.

    #include 
    
    int main(void) {
        // your code goes here
        int a = 5;
    
        printf ("%p = %i\n", (void*) &a, a);
        a = 10;
        printf ("%p = %i\n", (void*) &a, a);
    
        return 0;
    }
    

提交回复
热议问题