• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Scope of variables
 

 

Statistics

Views

Total Views
72
Views on SlideShare
72
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Scope of variables Scope of variables Presentation Transcript

    • Sreyachandran.v Sreya.chandran31@gmail.com www.facebook.com/sreyachandran twitter.com/username in.linkedin.com/in/profilename Scope of variable in C
    • Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
    • Scope of variable •Refers to where variables can be referenced •There are three places where variables can be declared in c programming language 1. Local variable 2. Global variable 3. Formal parameters
    • Local variable • Variables that are declared inside a function or block are called local variables. • They can be used only by statements that are inside that function or block of code. function_1() { data_type a; }
    • • Example #include<stdio.h> main() { int a=5; ++a; printf("%d", a); increment(); return 0; } void increment() { ++a; printf("%d", a); } Error : function is trying to access local variable of main()
    • Global variable • Global variables in c have their declaration outside the function definition of all functions used within the program. • They remains in the memory as long as the program is executing.
    • • Example #include<stdio.h> int a=5; main() { ++a; printf("%dn", a); increment(); return 0; } void increment() { ++a; printf("%dn",a); } Output 6 7
    • Nested scope • Local variables of same name can be nested inside global variables. int total = 5; int main ( ) { int total = 4; …. } int sub1 ( ) { int i = total; } Nested scope
    • • Example #include<stdio.h> int f1(); int a=10; main() { int a=20; int b=f1(); printf(“%dn % d”, a , b); } f1(int x) { x=a; return x; } Using local variable ‘a’ Using global variable ‘a’ Output 20 10
    • Want to learn more about programming or Looking to become a good programmer? Are you wasting time on searching so many contents online? Do you want to learn things quickly? Tired of spending huge amount of money to become a Software professional? Do an online course @ baabtra.com We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.
    • Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Give a feedback @ massbaab.com/baabtra Thanks in advance www.baabtra.com | www.massbaab.com |www.baabte.com
    • Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com Contact Us