Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Craps Game and Storage Classes in C Programming, Slides of Computer Fundamentals

An example of a craps game simulation and explains the concept of storage classes in c programming. The craps game rules are outlined, and the program output is shown. Additionally, the document covers the three types of storage classes: automatic, static, and external, as well as their respective properties such as storage duration, scope, and linkage.

Typology: Slides

2011/2012

Uploaded on 07/31/2012

karthik
karthik 🇮🇳

4.6

(16)

95 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
.
5.10 Example: A Game of Chance
Craps simulator
Rules
Roll two dice
7 or 11 on first throw, player wins
2, 3, or 12 on first throw, player loses
4, 5, 6, 8, 9, 10 - value becomes player's "point"
Player must roll his point before rolling 7 to win
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Craps Game and Storage Classes in C Programming and more Slides Computer Fundamentals in PDF only on Docsity!

5.10 Example: A Game of Chance

• Craps simulator

• Rules

– Roll two dice

• 7 or 11 on first throw, player wins

• 2, 3, or 12 on first throw, player loses

• 4, 5, 6, 8, 9, 10 - value becomes player's "point"

– Player must roll his point before rolling 7 to win

Outline

fig05_10.c (Part 1

of 4)

Outline

fig05_10.c (Part 3

of 4)

Outline

fig05_10.c (Part 4

of 4)

5.11 Storage Classes

• Storage class specifiers

– Storage duration – how long an object exists in memory

– Scope – where object can be referenced in program

– Linkage – specifies the files in which an identifier is known

(more in Chapter 14)

• Automatic storage

– Object created and destroyed within its block

– auto: default for local variables

auto double x, y;

– register: tries to put variable into high-speed registers

• Can only be used for automatic variables

register int counter = 1;

5.11 Storage Classes

• Static storage

– Variables exist for entire program execution

– Default value of zero

– static: local variables defined in functions.

• Keep value after function ends

• Only known in their own function

– extern: default for global variables and functions

• Known in any function

5.12 Scope Rules

• Block scope

– Identifier declared inside a block

• Block scope begins at definition, ends at right brace

– Used for variables, function parameters (local variables of

function)

– Outer blocks "hidden" from inner blocks if there is a variable

with the same name in the inner block

• Function prototype scope

– Used for identifiers in parameter list

Outline

fig05_12.c (Part 1

of 3)

Outline

fig05_12.c (Part 3

of 3)

Outline

Program Output

local x in outer scope of main is 5 local x in inner scope of main is 7 local x in outer scope of main is 5 local x in a is 25 after entering a local x in a is 26 before exiting a local static x is 50 on entering b local static x is 51 on exiting b global x is 1 on entering c global x is 10 on exiting c local x in a is 25 after entering a local x in a is 26 before exiting a local static x is 51 on entering b local static x is 52 on exiting b global x is 10 on entering c global x is 100 on exiting c local x in main is 5