Tuesday 25 December 2012

C/C++ Puzzles: PART - 5


There are no Automatic Global Variables

 Consider the program given below.

#include<stdio.h>
auto int aaa;
int main()
{
    aaa=222;
    printf("Value is %d\n",aaa);
    return 0;
}



Download

When you compile the program you will get the following error, "file-scope declaration of 'aaa' specifies 'auto' ". Reason? Global variables should never be declared as automatic variables (auto).

The following program given below works properly.

#include<stdio.h>
int aaa;
int main()
{
    aaa=222;
    printf("Value is %d\n",aaa);
    return 0;
}

Download 

The Figure Given Below Shows the Output

No comments:

Post a Comment