Storage Classes.

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.
Functions and scope Confidence In scope Reference: K&K textbook, Chapter 4.
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.
Methods of variable creation Global variable –declared very early stage –available at all times from anywhere –created at the start of the program, and.
C Lecture Notes Functions (Cont...). C Lecture Notes 5.8Calling Functions: Call by Value and Call by Reference Used when invoking functions Call by value.
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.
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
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.
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.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Senem Kumova Metin // CS115 // FUNCTIONS continues CHAPTER 5.
UNIT III. Functions  To divide a big program into a number of relatively smaller and easily manageable subprograms. Each subprogram in C is called a.
Functions Kernighan/Ritchie: Kelley/Pohl: Chapter 4 Chapter 5.
PASSING VALUE TO A FUNCTION # CALL BY VALUECALL BY VALUE # CALL BY REFERENCECALL BY REFERENCE STORAGE CLASS # AUTOAUTO # EXTERNALEXTERNAL # STATICSTATIC.
Data Types. Data types Data type tells the type of data, that you are going to store in memory. It gives the information to compiler that how much memory.
18. DECLARATIONS.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
 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.
Dale Roberts CSCI 230 Functions Scope, Parameter Passing, Storage Specifiers Department of Computer and Information Science, School of Science, IUPUI Dale.
FUNCTIONS. Funtions  The heart of effective problem solving is problem decomposition.  breaking a problem into small, manageable pieces  In C, the.
CSCI 171 Presentation 6 Functions and Variable Scope.
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.
Chapter 6: Function Introduction to function Standard functions User defined functions –function prototype –function definition Function call Storage classes.
+ Storage Classes and Linkage. + Introduction Scope describe the region or regions of a program that can access and identifier Variables can be shared.
Senem Kumova Metin // CS115 // FUNCTIONS CHAPTER 5.
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
The Three Attributes of an Identifier
C Functions -Continue…-.
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
Storage class in C Topics Automatic variables External variables
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
Computer Organization & Compilation Process
Advanced Programming Basics
Local Variables, Global Variables and Variable Scope
CSC 253 Lecture 7.
C Storage classes.
Storage class.
Scope Rules Of Variables
In C Programming Language
STORAGE CLASS.
Computer Organization & Compilation Process
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.
INTRODUCTION TO C.
Storage Classes.
Presentation transcript:

Storage Classes

Storage Classes Storage class tells : 1) Where the variable is stored. 2) Initial value of the variable. 3) Scope of the variable. (which a variable is accessed.) 4) Life of the variable.

Storage Classes There are four types of storage classes: 1) Automatic storage class 2) Register storage class 3) Static storage class 4) External storage class

Storage Classes Automatic storage class Variable is stored in memory. Default value is garbage value Scope is local to the block where it is declared Life is, with in the block in where it is declared Automatic variable can be declared using the keyword auto Eg: auto int a; By default all variables are automatic int a; same as auto int a;

Storage Classes Example 1: main() { auto int i=10; printf(“%d”,i); } Output: 10 Example 2: auto int i; 1002 In example 1, i value is initialised to 10.So,output is 10. In example 2, i value is not initialized. So,compiler reads i value is a garbage value.

Storage Classes Register storage class Variable is stored in a register instead of RAM. Default value is garbage value Scope is local to the block where it is declared Life is, with in the block in where it is declared

Storage Classes Register storage class When a variable stored in register, it access high speed The no of registers are limited in a processor, if the registers are not free it will convert to automatic variable The mostly length of the registers are 2 bytes, so we cannot store a value greater than its size, if it so it will covert to automatic variable Register variable can be declared using the keyword register Eg: register int a;

Storage Classes Static - Storage Class Variable is stored in memory. Default value is 0 Scope local to the block. Life is, value of the variable persists between different function calls. static variable can be declared using the keyword static Eg: static int a;

Storage Classes Static - Storage Class static can also be defined within a function. The variable cannot reinitialized when the function is called. This inside a function static variable retains its value during various calls. main() { void show(); show(); } void show() { static int a=10; printf(“%d”,a); a++; o/p will be 10 11 second time a=10; will not execute

Storage Classes External - Storage Class Variable is stored in memory. Default value is 0 Scope is end of the program Life is, with in the block in end of the program external variable can be declared using the keyword extern extern is used to give a reference of a global variable that is visible to ALL the program files.

Storage Classes External - Storage Class extern int a=10; void main() { vid show(); printf(“a= %d”,a); show(); } void show() printf(“%d”,a); Output a=10 10

Storage Classes External - Storage Class The extern keyword is used before a variable to inform the compiler that the variable is declared some where else.