Tuesday, 11 July 2017

Auto variable

Auto variable "C" Language


Auto or local variable in c language is a type of variable which space allocate and deallocate space automatically and static in by nature. An auto variable is invisible from outside of a function or block. So an auto variable can be access within the block where it is defined. By default all variable in a block or function is auto by nature. Auto keyword is used to make auto variable which is optional.

Auto int a;

Or

Int a


#include<stdio.h>
void main()
{
     int a=10;

     {
          int b=20;
          {
              int c=30;
              printf("%d%d%d",a,b,c);
          }
          printf("%d%d%d",a,b,c); /* Error Undefined symbol c */
     }
     printf("%d%d%d",a,b,c); /* Error Undefined symbol b and c */
     getch();

}

Given program will not be run and produce given error message because when we try to use a variable out of its block or scope then it will not be used because compiler frees space allocated by a variable.


No comments:

Post a Comment