Tushar33
Uploaded by
10 SLIDES
111 VIEWS
110LIKES

Presentation

DESCRIPTION

This is a piece of art which takes time to build up.

1 / 10

Download Presentation

Presentation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GLOBAL AND LOCAL DECLARATION

  2. SCOPE The Scope of a declaration is the block of code where the identifier is valid for use. A global declaration is main outside the bodies of all functions and outside the main program. It is normally grouped with the other global declarations and placed at the beginning of the program file. A local declaration is one that is made inside the body of a function. Locally declared variables cannot be accessed outside of the function they can be declared in. It is possible to declare the same identifier name in different parts of the programe. j

  3. LOCAL VARIABLE TO A  FUNCTION Pellentesque semper enim eu orci efficitur pretium. Proin non sapien elementum, convallis diam sed, dapibus ipsum. Maecenas ut massa ornare, consectetur lorem eu, feugiat purus. Aenean elementum nisl id eros luctus tincidunt. Nunc ac metus eget massa imperdiet molestie. Etiam faucibus turpis eget laoreet iaculis.

  4.               FORMAL PARAMETER ARE LOCAL TO A FUNCTION All variable/constants in the formal parameters and inside the body are local to the function They can not be used by others They are short-lived: they come when the function is called, and go when the function returns.

  5. Block Scope is local within a pair of brackets{...} For, while, do-while, if, else, switch, etc. All variables/constants in the block are local to the block They cannot be used out of the block They are short-lived as well: they come when the block is entered, and go when the block is finished.

  6. GLOBAL VARIABLES int x; int main() { x=0; count<<x<<end; int b; b=1; { int c; c=2; count<<c<<end; } count<<c<<end; }

  7. Global is 'file' scope Global variable are initialized to 0 when not explicitly initialized Global variable can be accessed by anyone in the same file When a global variable is used in a different file, it needs to have a 'external declaration'. Functions are all 'Global' When a function is used in a different file, it needs to be re-declared

  8. BIG TEXT Undisciplined use of global variables may lead to confusion and debugging difficulties. Instead of using global variables in functions, try passing loacl variables by reference.

  9. EXAMPLE int num; //global variable void increment(int& num) {num=num+1; count< number=number+1;} void main(){ number=1; increment(number); count<,number< } When increment is called,Num refers to global variable number Number=Number+1 also refers to global variable Number.

  10. THANK YOU!

More Related