Right Click to Search

Sunday, January 24, 2025

Scope of Variable in C : Compile Error




Scope of Variable :

#include"stdio.h"
void message();
void main()
{
 int num1 = 6 ;
 printf("%d",num1);
 message();
}
void message()
{
 printf("%d",num1);
}

Output of Above Program :
  • Compile Error : Variable num1 is visible only within main function , It cannot be accessed by other function

Definition of Scope of Variable  : 
Scope of variable is defined as Region or Part of Program in which the variable is visible / accessed / valid .

Rules of Scope of Variable : 
  1. Local Variables are accessed / Visible only in Local Block
  2. Global variables can be explained from anywhere in program
  3. Priority is Given to Local variable if the two variables are declared with same name,type but in different blocks/functions

    Bookmark & Share

    Tags / Keywords : | ,

    Stumble
    Delicious
    Technorati
    Twitter
    Facebook

    0 Comments:

    Post a Comment

    Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

     

    Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates