Home » C programming language

Automatic (auto) variables in c language

The variables which are declared inside a block are known as automatic or local variables; these variables allocates memory automatically upon entry to that block and free the occupied memory upon exit from that block.

These variables have local scope to that block only that means these can be accessed in which variable declared.

Keyword 'auto' may be used to declare automatic variable but we can declare these variable without using 'auto' keywords.

Consider the following declarations

    int main()
	    auto int a;
	    int b;
	    return 0;

Here, both variables a and b are automatic variables.

Automatic variables in other user defined functions

An automatic or local variable can be declared in any user define function in the starting of the block.

Consider the following code

void myFunction(void)
	int x;
	float y;
	char z;

int main()
	int a,b;
	return 0;

In this code snippet, variables x, y and z are the local/automatic variable of myFunction() function, while variables a and b are the local/automatic variables of main() function.

Comments and Discussions

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.