Saturday, February 18, 2012

sample program to avoid confusion with auto and register storage classes....

//Program tested on Microsoft Visual Studio 2008  
 #include<iostream>
using namespace std;

int main()
{
 int i = 123;
 auto int j = 456;
 register int k = 789;

 cout<<"Address of i = " << &i <<", Value = " << i << endl;
 cout<<"Address of j = " << &j <<", Value = " << j << endl;
 cout<<"Address of k = " << &k <<", Value = " << k << endl;

 return 0;
}

2 comments:

  1. Note that the address of i, j and k are very close implying that the compiler chose to ignore the 'register' keyword.

    ReplyDelete
  2. The register keyword serves very little function, offering no more than a hint that a note says is typically ignored. It should be deprecated in this version of the standard, freeing the reserved name up for use in a future standard, much like auto has been re-used this time around for being similarly useless.

    ReplyDelete