6 Replies - 328 Views - Last Post: 16 October 2019 - 09:41 AM Rate Topic: -----

#1 FreddoMayano   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 32
  • Joined: 11-October 19

Updating new data to specific element/variable

Posted 14 October 2019 - 07:53 AM

Hi guys, please bear me up because it's every time shaking me up and down while coding ..
lets say I have a code like this
int a=5;
a=6;


so the value of a is 6 and not 5, I deeply believe that the recent updated value to variable is the value of the variable, but so confused about the previous value before updating .. it's will be deleted once we are updating .. so I just need to know that? I mean I'm not fully convinced about that because we are in real life not tolerated to this situation the previous value deleted automatically once new values change it ..
so if I explain to a child who's 10years old the previous value will be deleted so he will be sudden up, and if he asks me why then I have no clue because that's how PC WORKS
my question, is there a good explanation in order to explain to myself why the previous value gets deleted once new value comes instead ?

Much appreciated, apologized for this shitty thinking but yeah I want to learn how PC works to be a good programmer ..

Is This A Good Question/Topic? 0
  • +

Replies To: Updating new data to specific element/variable

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15308
  • View blog
  • Posts: 61,390
  • Joined: 12-June 08

Re: Updating new data to specific element/variable

Posted 14 October 2019 - 08:03 AM

It's not deleted. It's over written.
Was This Post Helpful? 1
  • +
  • -

#3 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 981
  • View blog
  • Posts: 3,868
  • Joined: 13-June 14

Re: Updating new data to specific element/variable

Posted 14 October 2019 - 10:31 AM

Makes me think of something RyanMco would ask.
Was This Post Helpful? 2
  • +
  • -

#4 FreddoMayano   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 32
  • Joined: 11-October 19

Re: Updating new data to specific element/variable

Posted 14 October 2019 - 04:23 PM

View Postmodi123_1, on 14 October 2019 - 08:03 AM, said:

It's not deleted. It's over written.

what does "over-written" mean in computing world?

View Postndc85430, on 14 October 2019 - 10:31 AM, said:

Makes me think of something RyanMco would ask.

have no clue on what you're talking sir, really sorry.
Was This Post Helpful? -1
  • +
  • -

#5 unixplumber   User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 13
  • Joined: 02-January 19

Re: Updating new data to specific element/variable

Posted 15 October 2019 - 02:20 PM

Think of a variable like a row of light switches. Each light switch either turns on or off or stays the same when you change its value. One moment the variable is "off off on on", and the next moment it's "on on on on". Was "off off on on" deleted? No, the state of some of the light switches simply changed.

So you can see that it doesn't make sense to ask about the old value being "deleted". It's like asking why a light switch's "off" value is deleted when you turn the light on.
Was This Post Helpful? 0
  • +
  • -

#6 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7492
  • View blog
  • Posts: 15,527
  • Joined: 16-October 07

Re: Updating new data to specific element/variable

Posted 16 October 2019 - 04:53 AM

Programming languages are said to have grammars. Unlike human languages, there is very little ambiguity in computer languages; everything is has significance and meaning.

So:
int /* allocate enough memory to store an int */
a /* call that storage location a */
= /* this is the C++ operator for assignment, the next token will be placed in the storage location labeled a */
5; /* the literal 5 is now stored in the memory location known as a */

a = /* store a value in location known as a */
6; /* the literal 6 is now stored in the memory location known as a */



As this code is fundamentally simple, you could actually generate the assembly language and see how a computer really thinks about these things at a machine level. However, it's near identical to the above.
Was This Post Helpful? 0
  • +
  • -

#7 unixplumber   User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 13
  • Joined: 02-January 19

Re: Updating new data to specific element/variable

Posted 16 October 2019 - 09:41 AM

To be pedantic, the = 5 part of int a = 5; is an initializer rather than an assignment.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1