Why don't some languages allow declaration of pointers?

前端 未结 7 1673
半阙折子戏
半阙折子戏 2020-12-31 05:41

I\'m programming in C++ right now, and I love using pointers. But it seems that other, newer languages like Java, C#, and Python don\'t allow you to explicitly declare point

7条回答
  •  暖寄归人
    2020-12-31 06:21

    I try to answer OP's question directly:

    In other words, you can't write both int x and int * y, and have x be a value while y is a pointer, in any of those languages. What is the reasoning behind this?

    The reason behind this is the managed memory model in these languages. In C# (or Python, or Java,...) the lifetime of resources and thus usage of memory is managed automatically by the underlying runtime, or by it's garbage collector, to be precise. Briefly: The application has no control over the location of a resource in memory. It is not specified - and is even not guaranteed to stay constant during the lifetime of a resource. Hence, the notion of pointer as 'a location of something in virtual or physical memory' is completely irrelevant.

提交回复
热议问题