Skip to Main Content
C Programming: Visual Quickstart Guide
book

C Programming: Visual Quickstart Guide

by Larry Ullman, Marc Liyanage
October 2004
Beginner content levelBeginner
408 pages
9h 24m
English
Peachpit Press
Content preview from C Programming: Visual Quickstart Guide

Understanding Variable Scope

The final topic we'll discuss in this chapter is variable scope—in other words, where variables exist. This is pertinent to functions because variables within a function are not accessible by code outside a function. And, for that matter, variables outside a function are not necessarily accessible inside the function.

Understanding Static Variables

Variables within functions are different not only because of variable scope but also because they can be static. Let's start with this example:

void up_one (void) {
   int num = 0;
   printf ("%d\n", ++num);
}

Even though num is incremented with each up_one() call, its ending value will only be 1 because it's reinitialized to 0 each time the function is called. In other words, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intermediate C Programming

Intermediate C Programming

Yung-Hsiang Lu
Data Structures Using C

Data Structures Using C

Samir Kumar Bandyopadhyay, Kashi Nath Dey

Publisher Resources

ISBN: 0321287630Purchase book