UMBC CS 201, Spring 99
UMBC CMSC 201 Spring '99 CSEE | 201 | 201 S'99 | lectures | news | help

local

The Program

/* File: local.c A program to demonstrate local variables. */ #include <stdio.h> /* Function Prototypes */ void RedFish (int i); void BlueFish (int n); main () { int n; n = 17; printf("Before calling RedFish, n = %d\n", n); RedFish (32); printf("After calling RedFish, n = %d\n", n); printf("\n"); printf("Before calling BlueFish, n = %d\n", n); BlueFish (n); printf("After calling BlueFish, n = %d\n", n); } /* The function RedFish illustrates the idea of local variables */ void RedFish (int i) { int n; i = 2; n = 14; printf(" In RedFish, i = %d, n = %d\n", i, n); return; } /* The function BlueFish illustrates the idea of local variables */ void BlueFish (int n) { n = 72 ; printf(" In BlueFish, n = %d\n", n); return ; }

The Sample Run

Before calling RedFish, n = 17 In RedFish, i = 2, n = 14 After calling RedFish, n = 17 Before calling BlueFish, n = 17 In BlueFish, n = 72 After calling BlueFish, n = 17

The Lesson


CSEE | 201 | 201 S'99 | lectures | news | help

Wednesday, 17-Feb-1999 14:03:42 EST