CSE101-Lec#16.pptx - CSE101-lec#16 Storage Classes and Scope Rules \u00a9LPU CSE101 C Programming Created By Amanpreet Kaur Sanjeev Kumar SME(CSE LPU

CSE101-Lec#16.pptx - CSE101-lec#16 Storage Classes and...

This preview shows page 1 - 9 out of 25 pages.

©LPU CSE101 C Programming Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU CSE101-lec#16 Storage Classes and Scope Rules
Image of page 1
©LPU CSE101 C Programming Outline Storage Classes auto static extern register Scope Rules
Image of page 2
©LPU CSE101 C Programming Storage Classes Storage class specifies Storage duration – how long the variable retains a particular value Scope – or visibility of the variable i.e the portion of the program within which the variables are recognized. The duration of existence is for few seconds only Scope limited to the function calculating the distance travelled/lef
Image of page 3
©LPU CSE101 C Programming Storage Classes: Auto Automatic storage auto int x, y; It is the default storage class Storage − Memory. Default initial value − An unpredictable value, which is ofen called a garbage value. Scope − Local to the block in which the variable is defined. Life − Till the control remains within the block in which the variable is defined .
Image of page 4
©LPU CSE101 C Programming Storage Classes: Register register: tries to put variable into high-speed registers. register int counter = 1; Storage - CPU registers . Default initial value - Garbage value. Scope - Local to the block in which the variable is defined. Life - Till the control remains within the block in which the variable is defined.
Image of page 5
©LPU CSE101 C Programming Storage Classes: Static Static storage Storage − Memory. Default initial value − Zero. Scope − Local to the block in which the variable is defined. Life − variable will retain throughout the program Qu Di of ex da st a s
Image of page 6
©LPU CSE101 C Programming Storage Classes: extern Default for global variables and functions Known in any function Storage − Memory . Default initial value − Zero . Scope − Global . Life − As long as the program’s execution doesn’t come to an end.
Image of page 7
©LPU CSE101 C Programming Scope Rules The scope of a variable is the portion of a program where the variable has meaning (where it exists). A global variable has global (unlimited) scope. A local variable’s scope is restricted to the function that declares the variable.
Image of page 8
Image of page 9

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture