Automatic Variables & External Variables

A variable declared within a function cannot be accessed directly by another function. The variable declared in main function of a program cannot be accessed directly by another function. These kind of variables are called Automatic Variables.The variable come into existence when the corresponding function is invoked and it perishes when the function terminates.

Another type of variable is called External Variable. These variables are globally accessible and its existence is permanent.

The external variables must be defined outside any function and it should be declared within the function which need to access it.The declaration is done using an explicit extern statement.

The extern declaration can be omitted when the definition of the external variable occurs in the source file before its use in a particular function. Usually extern declarations are stored in a separate file called header and can be used similar to <stdio.h> i.e. #include<header name.h>.

Sometimes usage of external variable can cause problems in a program. The variable could be modified by any function within the program, which is undesirable in majority of situations.

Advertisements

About Odol Shinu

I've completed my B Tech in Information Technology in 2010 from Government Engineering College Sreekrishnapuram Palakkad under Calicut University.

Posted on August 6, 2010, in C Language. Bookmark the permalink. 1 Comment.

  1. Please post to the mailing list when you update the blog.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: