Pages: [1]   Go Down
Author Topic: Gobal Variable Value Persistence  (Read 307 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know this is elementary, but I've looked in my C programming books and can't find the answer.
Global Variables declared with a value.
I assume that unlike function local variables, which are not retained and re-initialized between calls, global variables that have values updated inside a function retain that value the next time the function is called, that is, until the variable is assigned a new value.

Is that true?

Thanks,
John
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,

John
Logged

Sydney, Australia
Online Online
Edison Member
*
Karma: 33
Posts: 1273
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just to add some more info, you can add static in front of variables in functions and they will persist between calls whilst still retaining the function-only scope.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Pages: [1]   Go Up
Jump to: