Variables, Values, Memory

Variables Values, - definitions and statements • Global variables are defined outside the body of every function in the file(lifetime of the main

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Variables, Values, Memory A value is an abstract concept A memory location or storage is a place where a value can be stored A variable is an identification of some memory A variable is an lvalue Can have a (new) value assigned to it Almost everything has a value
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
7: Scope The lifetime of a variable is the period of time during which memory is allocated to the variable Since storage is freed in the reverse order of allocation, a stack is a convenient data structure to represent it with (the run time stack )
Background image of page 2
7: Blocks and Global Variables A block is like a compound statement, enclosed in braces, and it may contain both
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: definitions and statements. • Global variables are defined outside the body of every function in the file (lifetime of the main program): • int flag = 0; /* global */ • int f() { • … Global variables • Global variables should be used with caution, and always carefully documented . Changing the value of a global variable as a result of calling a function should be avoided; these side-effects make testing, debugging, and in general maintaining the code very difficult. • The placement of the definition of a global...
View Full Document

This note was uploaded on 02/18/2012 for the course CS 240 taught by Professor Rego during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 4

Variables Values, - definitions and statements • Global variables are defined outside the body of every function in the file(lifetime of the main

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online