Local and Global Variables in C

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

// Local and global variables 
#include<stdio.h>
#include<conio.h>
int main()
{  
    system("cls");
      int a=10;
      {
            int a=20;
         { 
              int a=30;
             {
                       int a=40;
                       printf("\n %d",a);
             }
             printf("\n %d",a);
         }
         printf("\n %d",a);
      }
      printf("\n %d",a);
    return 0;  
}














// int a=10;
// void abc();
// void xyz();
// int main()
// {
//     system("cls");
//     int a=100;                                 // a=100
//     abc();
//     printf("\n%d",a);                        //100         3
//     return 0;
// }
// void abc()
// {
//      a=a+20;    // a=30
//      xyz();
//      printf("\n%d",a);              // 30                    2
// }
// void xyz()
// {
//       int a=500;                      // a=550
//       a=a-50;
//       printf("\n%d",a);                // 450              1 
//       a=a+100;
// }












//int a=100;
//void display();
// int main()
// {
//      system("cls");
     
//      {
//           int a=500;
//            a=a+10;   
//            printf("%d",a); //510
//      }
//      printf("\n inside main: %d",a); //100
    
//     return 0;
// }
// void display()
// {
//      printf("\n inside display: %d",a);
// }

 

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *