Variables are local, or private, to their functions, which means that the variable's contents are discarded when a function quits. To have a function's variable retain its value, it's declared as a static type as opposed to auto, which ensures that the variable's value is retained.
- [Instructor] Variables are private to their functions. … In this code, both the main and funct functions … use integer variable a, … the variable is assigned a value in each function, … and this value is independent despite the variable's name … and despite it being used in both functions. … Build and run, … and you can see that the value … is independent of what goes on in the other functions. … A variable name is just a name. … In this source code file, however, … I desire to have the same value used in both functions. … In this code, however, … I desire to have the value of variable a in function funct … be returned, not only that, … to have its value retained between function calls. … So at line seven, the variable's value is increased by 16. … This variable is output, its value is output here, … and then it's returned to the main function. … Now in the main function, … this value is saved in its variable a and output … but then the function calls again, and again, … each time, the desire is to have the variable …
- Writing your first C program
- Working the C development cycle
- Adding comments to code for clarity
- C language data types
- Declaring variables
- Making new data types
- Typecasting variables
- Using math, assignment, and logical operators
- Creating for and while loops
- Nesting loops
- Creating functions
- Returning values from functions
- Passing arguments to functions
- Creating recursive functions
Skill Level Intermediate
C: Data Structures, Pointers, and File Systemswith Dan Gookin2h 57m Intermediate
1. The Fundamentals of C
2. Variables and Values
3. Operators and Math
4. Decisions and Loops
Next steps1m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.