Thursday, April 12, 2012
Auto storage class in C!!
Auto is the default storage class for the local varaibles. Auto is a short form for Automatic.
OutPut:
a is 0
i is 0
In the above code, two integer variables are declared as automatic , in that one is using keyword and another one is without keyword. both variables behaviour is same. They are not inittialised, so default value is garbage value. Here in the output , it is zero. Defualt value is depends on the machine. I am using Unix, so got default value zero. If you use Windows , you may get garbage value. So if you not initialise the variable, result is undefined. So its always better to initialise the variables.
Variable initialization:
OutPut:
a is 20
i is 20
In the above code, two integer variables are declared as automatic , in that one is using keyword and another one is without keyword. both variables behaviour is same.
Scope or visibility sample code:
OutPut:
a is 30
i is 20
a is 20
In the above code, on integer varibale a is declared in a main block, another two variabels a and i declared in the separted block. second variable a and i are limited to this block only. If second variable is not declared in the block, first declared a variable scope comes to this block also.
- Keyword : auto
- Default value : Garbage value
- Memory Location : Main memory
- Scope : Local to the block or function
- Lifetime : Till the application runs or until memory location destroys
int main() { auto int a; int i; printf("a is %x\ni is %d\n",a,i); }
OutPut:
a is 0
i is 0
In the above code, two integer variables are declared as automatic , in that one is using keyword and another one is without keyword. both variables behaviour is same. They are not inittialised, so default value is garbage value. Here in the output , it is zero. Defualt value is depends on the machine. I am using Unix, so got default value zero. If you use Windows , you may get garbage value. So if you not initialise the variable, result is undefined. So its always better to initialise the variables.
Variable initialization:
int main() { auto int a=20; int i=20; printf("a is %x\ni is %d\n",a,i); }
OutPut:
a is 20
i is 20
In the above code, two integer variables are declared as automatic , in that one is using keyword and another one is without keyword. both variables behaviour is same.
Scope or visibility sample code:
int main() { auto int a=20; { int a = 30; // scope is limited to this block int i=20; // scope is limited to this block printf("a is %d\ni is %d\n",a,i); } // we cant access i here // a is first declared variable and not the second declared variable printf("a is %d\n",a); }
OutPut:
a is 30
i is 20
a is 20
In the above code, on integer varibale a is declared in a main block, another two variabels a and i declared in the separted block. second variable a and i are limited to this block only. If second variable is not declared in the block, first declared a variable scope comes to this block also.
Subscribe to:
Post Comments (Atom)
Popular Posts
-
A universally unique identifier ( UUID ) is an identifier standard used in software construction, standardized by the Open...
-
Recently I started working on Japser Studio professional for my new project Cloud to generate the reports. I was very new to all cloud ...
-
Below is C program for AVL Tree implementation. #include<stdio.h> #include<malloc.h> typedef struct bst { int info; int hei...
-
strcmp is another string library function which is used to compare two strings and returns zero if both strings are same , returns +ve valu...
-
One of the complex operation on binary search tree is deleting a node. Insertion is easy by calling recursive insertion. But deletion wont...
-
We have recently faced one tricky issue in AWS cloud while loading S3 file into Redshift using python. It took almost whole day to inde...
-
Object slicing: when a derived class object is assigned to a base class object. only base class data will be copied from derived class and...
-
We have faced lot of weird issues while loading S3 bucke t files into redshift. I will try to explain all issues what we faced. Before go...
-
Below code is to find the cube root of a given integer number with out using pow math library function. Its very simple and brute force...
-
Recently we faced one issue in reading messages from SQS in AWS cloud where we are processing same message multiple times. This issue we...
No comments:
Post a Comment