Storage class.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Advertisements

Storage class in C Topics Automatic variables External variables
1 Storage Duration and Scope –Local and global variables Storage classes –automatic, static, external, register Todays Material.
Programming In C++ Spring Semester 2013 Lecture 12 Programming In C++, Lecture 12 By Umer Rana.
Copyright © 2000, Daniel W. Lewis. All Rights Reserved. CHAPTER 9 MEMORY MANAGEMENT.
Chapter 7: User-Defined Functions II
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Scope Rules and Storage Types CS-2303, C-Term Scope Rules and Storage Types CS-2303, System Programming Concepts (Slides include materials from The.
Methods of variable creation Global variable –declared very early stage –available at all times from anywhere –created at the start of the program, and.
Overview scope - determines when an identifier can be referenced in a program storage class - determines the period of time during which that identifier.
Storage & Linkage: Effects on Scope Rudra Dutta CSC Spring 2007, Section 001.
Storage Classes.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2013 CMPE-013/L Modules and Scope Gabriel Hugh Elkaim Spring 2013.
C++ for Engineers and Scientists Third Edition
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
CSCI 130 Scope of Variables Chapter 6. What is scope Parts of program which can access a variable –accessibility –visibility How long variable takes up.
chap13 Chapter 13 Programming in the Large.
Copyright 2001 Oxford Consulting, Ltd1 January Storage Classes, Scope and Linkage Overview Focus is on the structure of a C++ program with –Multiple.
C Functions Programmer-defined functions – Functions written by the programmer to define specific tasks. Functions are invoked by a function call. The.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Chapter 6: Modularity Using Functions. In this chapter, you will learn about: – Function and parameter declarations – Returning a single value – Returning.
MAHENDRAN CHAPTER 6. Session Objectives Explain Type of Functions Discuss category of Functions Declaration & Prototypes Explain User Defined Functions.
PASSING VALUE TO A FUNCTION # CALL BY VALUECALL BY VALUE # CALL BY REFERENCECALL BY REFERENCE STORAGE CLASS # AUTOAUTO # EXTERNALEXTERNAL # STATICSTATIC.
18. DECLARATIONS.
Learners Support Publications Classes and Objects.
CS 2130 Lecture 5 Storage Classes Scope. C Programming C is not just another programming language C was designed for systems programming like writing.
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
 2007 Pearson Education, Inc. All rights reserved Random Number Generation  rand function – Load – Returns "random" number between
C++ Programming Lecture 11 Functions – Part III By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
ECE 103 Engineering Programming Chapter 36 C Storage Classes Herbert G. Mayer, PSU CS Status 8/4/2014 Initial content copied verbatim from ECE 103 material.
C++ Lecture 2 Friday 11 July Chapter 3, Functions l built-in functions l function prototype, function definition and use l storage class and scope.
Dale Roberts CSCI 230 Functions Scope, Parameter Passing, Storage Specifiers Department of Computer and Information Science, School of Science, IUPUI Dale.
Week 11 Multi-file Programs and Scope of Variables.
KIC/Computer Programming & Problem Solving 1.  Header Files  Storage Classes  Scope Rules  Recursion Outline KIC/Computer Programming & Problem Solving.
#include using namespace std; // Declare a function. void check(int, double, double); int main() { check(1, 2.3, 4.56); check(7, 8.9, 10.11); } void check(int.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
+ Storage Classes and Linkage. + Introduction Scope describe the region or regions of a program that can access and identifier Variables can be shared.
Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
1 This week Basics of functions Stack frames Stack vs. Heap (brief intro) Calling conventions Storage classes vs. scope Library functions Overloading.
Eine By: Avinash Reddy 09/29/2016.
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
C Functions -Continue…-.
C++.
Friend Class Friend Class A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful.
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
A Lecture for the c++ Course
Storage class in C Topics Automatic variables External variables
Chapter 5 Conclusion CIS 61.
trigraph ??= is for # ??( is for [ ??< is for { ??! is for |
Module 5 Sorting and Searching: Bubble sort Selection sort
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
Instructor: Ioannis A. Vetsikas
Scope, Parameter Passing, Storage Specifiers
CS 240 – Lecture 5 Scope of Variables, The Stack, Automatic Variables, Global Variables, Constant Type.
Local Variables, Global Variables and Variable Scope
Classes and Objects.
C Storage classes.
Scope Rules and Storage Types
Variables have attributes
Scope Rules Of Variables
In C Programming Language
Submitted By : Veenu Saini Lecturer (IT)
STORAGE CLASS.
STORAGE CLASS.
The Three Attributes of an Identifier
C Programming Lecture-17 Storage Classes
Storage classes in C In C language, each variable has a storage class which decides the following things: scope i.e where the value of the variable would.
Storage Classes.
Scope Rules.
Presentation transcript:

Storage class

Introduction We all know C++ is blocked structured language, so we can use the same variable in the C++ program in separate blocks i.e when we declare a variable it is available only to that block of program. The area or block of the C++ program where the variable can be accessed is known as Scope of variable Area or scope of the variable depend where on its storage class i.e where and how it is declared. Storage class of the variable tells the compiler Storage area of the variable Initial value of the variable Scope of variable Life of the variable i.e how long it would be active

Broadly storage class is classified as Local variable:-it is visible to the function in which it is declared. Declared inside the function Global variable :-it is visible to all the functions and it is outside the function. the proper place of declaring of global variable is at the beginning of the main program

Types of storage class Automatic variable External variable Static variable Register variable

Automatic variable It is a default storage class to be used within a program or file. defined and accessed within the function Local variables is also automatic variables b/c it is automatically created (when function is called) and automatically destroyed (when execution of function is complete) Auto variables are stored on to stack, which provides temporary storage Its default initial value is garbage value.

Example #include<iostream.h> #include<conio.h> void main() { int a=10; void func(); Cout<<a; func(); getch(); } void func() int a=20;

External variable The variable that are available to all the functions i.e entire program they can be accessed The scope of the variable is global. Its initial value is zero

example #include<iostream.h> #include<conio.h> int a; void main() { void func1(),func2(); a=a+1; cout<<a; func1(); func2(); getch(); }

void func1() { a=a+10; cout<<a; } void func2() a=a+5;

Static variable It is a storage similar to auto except that the variable once defined anywhere do not die till program ends the value of the variable will also be retained but will be accessed only by the function declaring it Static storage variable have initial value as zero

Example Void main() { void func(); func(); getch(); } Void func() static int a=0; a++; cout<<a;

Register variable We can also keep some variables in the cpu register(high speed memory near to the processor) instead of memory. The keyword register tells the compiler that variable is kept on the cpu register, since register is faster than memory access Register has Limited space, so if not space available it will treat variable as auto variables

Example #include<iostream.h> #include<conio.h> void main() { register int m=1; for(;m<=5;m++) cout<<m; } getch();

Summary STORAGE CLASS LIFE TIME SCOPE Auto Local Local(within function) External Global Global (in all function) Static Register