Right Click to Search

Sunday, January 24, 2025

Block Scope of Variable in C Programming




Block Scope of Variable :

  1. Block Scope is also called Local Scope
  2. It can be used only within a function or a block
  3. It is not visible outside the block
  4. Variables defined within local scope is called as Local variables
Definition :
Variable is said to have local scope / block scope if it is defined within function or local block
 Live Example :


#include"stdio.h"
void message();
void main()
{
 int num1 = 0 ;     // Local to main
 printf("%d ",num1);
 message();
}
void message()
{
 int num1 = 1 ;         // Local to Function message 
 printf("%d ",num1);
}


Output :
  • 0 1
Explanation :
  1. Program have two functions main and message
  2. In both functions we have declared variable 'num1'
  3. Both the variables have scope limited within the function body  
  4. Local variables are printed as output.
  5. In main value 0 is assigned to num1
  6. In function message value 1 is assigned to num1

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