UMBC CS 201, Fall 06
UMBC CMSC 201
Fall '06

CSEE | 201 | 201 F'06 | lectures | news | help

Tracing Programs

The Task

trace

The Program

/************************************************** * File: trace.c * * Author: S. Bogar * * Date: 2/2/96 * * Section: 101 * * EMail: bogar@cs.umbc.edu * * * * This program illustrates local variables and is * * to be used to demonstrate the techniques of * * tracing a program by hand. The non-meaningful * * function and variable names are intentional, * * since they are not REALLY doing anything that * * is meaningful except teaching you to trace * * function calls * **************************************************/ #include <stdio.h> int Foobar (int b); int Geez (int c); int main () { int a = 1, b = 2, c = 3; c = Geez (a); b = Foobar(c); printf("main: a = %d, b = %d, c = %d\n", a, b, c) ; return 0; } /********************************************* ** Function: Foobar ** Usage: Foobar(b); ** ** Input: an arbitrary integer, b ** Output: returns b++ ** outputs values of local vars, a common ** technique for debugging programs *********************************************/ int Foobar (int b) { int a, c; a = Geez (b); c = b++; printf("Foobar: a = %d, b = %d, c = %d\n", a, b, c); return (c); } /********************************************* ** Function: Geez ** Usage: Geez(c); ** ** Input: an arbitrary integer, c ** Output: returns c + 100 ** outputs values of local vars, a common ** technique for debugging programs *********************************************/ int Geez (int c) { int a, b; a = c + 100; b = 2 * a; printf("Geez: a = %d, b = %d, c = %d\n", a, b, c); return (a); }

The Sample Run

Geez: a = 101, b = 202, c = 1 Geez: a = 201, b = 402, c = 101 Foobar: a = 201, b = 102, c = 101 main: a = 1, b = 101, c = 101


CSEE | 201 | 201 F'06 | lectures | news | help

Tuesday, 22-Aug-2006 07:13:54 EDT