LectureThirteen - Lecture 13 Functions – Part III By...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Lecture 13 Functions – Part III By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department The Hashemite University 2 Outline ¡ Identifiers storage classes. ¡ Identifiers scope rules. ¡ Input/output manipulations. The Hashemite University 3 Introduction ¡ The main attributes attached with any program variable or identifier: ¡ Name, type, size, value (as taken before). ¡ Storage class ¡ Determines the period during which the variable exists in memory ¡ Scope ¡ Where the identifier can be referenced in program ¡ Linkage ¡ Where an identifier is known in multiple source file programs. The Hashemite University 4 Storage Classes ¡ Five storage-class specifiers: ¡ auto, ¡ register, ¡ extern, ¡ mutable, ¡ static. ¡ Storage classes types: ¡ Automatic storage. ¡ Static storage. The Hashemite University 5 Automatic Storage ¡ Variables created and destroyed within its block (created when entering the block and destroyed when leaving this block). ¡ Can only be used with local variables and parameters of a specified function. ¡ Two types: ¡ auto ¡ Default for local variables. ¡ Example: auto float x, y; ¡ register ¡ Tries to put variables into high-speed registers. ¡ The compiler can ignore it if no sufficient number of registers are available. ¡ Not necessary in optimized compilers. The Hashemite University 6 Static Storage ¡ Variables exist from the point of declaration for entire program execution. ¡ Static variables are created and initialized once when the program begins execution. ¡ Numeric variables are initialized to 0 by default unless the programmer initialize them explicitly. ¡ Two types: ¡ static ¡ Local variables defined in functions ¡ Keep value after function ends ¡ Only known in their own function. ¡ extern ¡ Default for global variables and functions. ¡ used to specify that the variable is declared in a different file. ¡ Known in any function. The Hashemite University 7 Storage Classes -- Notes ¡ Do not use multiple storage specifiers at the same time Æ syntax error. ¡ E.g.: register auto double x = 0; // syntax error ¡ mutable storage class is used with classes (in the object oriented classes). The Hashemite University 8 Identifier Scope Rules I ¡ Scope is where the identifier can be referenced in program. ¡ Scope Types: ¡ File scope: ¡ Defined outside a function, known in all functions ¡ Examples include, global variables, function definitions and functions prototypes ¡ Function scope: ¡ Can only be referenced inside a function body ¡ Only labels ( start: , case: , etc.) The Hashemite University 9 Identifier Scope Rules II ¡ Block scope: ¡ Declared inside a block. Declared inside a block....
View Full Document

This note was uploaded on 10/29/2010 for the course COMPUTER E 2010 taught by Professor Ghadaal-mashaqbeh during the Spring '10 term at Hashemite University.

Page1 / 22

LectureThirteen - Lecture 13 Functions – Part III By...

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

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