answersLogoWhite

0


Best Answer

It is not necessary to to declare variables inside the function in C. If you declare a variable inside a function, the variable becomes local for the function and another variable of same name can be declared in any other function, but you can not use the variable declared in other function. When you declare any variable outside the function body then the variable becomes global and can be used in any function of the program.

Note: errno is an example for a variable declared outside any function.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why all variables are declared with in the function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Which variable is not destroyed on exit from the function instead its value is presented and becomes available again when the function is next called These variables are declared as?

Local function variables defined static remain in memory at all times. Such variables are only in scope (accessible) when the function itself is in scope.


In java all variables declared using a class are?

Reference variables


whose variables are also known as global variables?

The variables which are declared outside the main() function is known as global variables and they can be used anywhere in the program. And, the variables which used declare inside the main() function is known as local variables and they can be used inside the main() function only. Example: #include<stdio.h> #include<conio.h> int x,y; // global variables void main() { int a,b; // Local variables ------------ ---------------------- --------------------- getch(); }


Why static variables in a function have global extent?

A variable declared static outside of a function has a scope the of the source file only. It is not a global variable. A variable declared outside of a function and without the static qualifier would be a global variable.


When variables are declared in the body of a method they are know as what?

Local Variables There are two types of variables based on the location of declaration 1. Instance Variables- Declared inside a class, but outside of any method's body. 2. Local Variables- Declared inside a method's body inside a class.

Related questions

Is it True or False that Variables declared in the particular member function are know as data members and can be used in all member functions of the class?

False. Variables declared within a particular member function are local to that function, and are automatically allocated and deallocated at entry and exit of the function.


Which variable is not destroyed on exit from the function instead its value is presented and becomes available again when the function is next called These variables are declared as?

Local function variables defined static remain in memory at all times. Such variables are only in scope (accessible) when the function itself is in scope.


In java all variables declared using a class are?

Reference variables


whose variables are also known as global variables?

The variables which are declared outside the main() function is known as global variables and they can be used anywhere in the program. And, the variables which used declare inside the main() function is known as local variables and they can be used inside the main() function only. Example: #include<stdio.h> #include<conio.h> int x,y; // global variables void main() { int a,b; // Local variables ------------ ---------------------- --------------------- getch(); }


Why static variables in a function have global extent?

A variable declared static outside of a function has a scope the of the source file only. It is not a global variable. A variable declared outside of a function and without the static qualifier would be a global variable.


What is the difference between a static variable a global variable and a local variable?

A static variable is a variable allocated in static storage. A local variable is a variable declared inside a function. A global variable is a variable declared outside of any class or function. Note that local variables and global variables can both be allocated in static storage.


When variables are declared in the body of a method they are know as what?

Local Variables There are two types of variables based on the location of declaration 1. Instance Variables- Declared inside a class, but outside of any method's body. 2. Local Variables- Declared inside a method's body inside a class.


Scope of static variables?

Scope of static variable is with in the file if it is static global. Scope of static variable is with in the function if variable is declared local to a function. But the life time is throughout the program


What are the differences between global variables and local variables in C plus plus?

Global variables can be seen in all blocks of your program, when local variables are visible only within the block where it's declared.


Is global variables are declared within the main function?

Might be, but don't forget the keyword 'extern':int main (void){extern int errno;...}


What is the difination of linear function?

A linear function is any function that graphs to a straight line. What this means mathematically is that the function has either one or two variables with no exponents or powers. If the function has more variables, the variables must be constants or known variables for the function to remain a linear function.


What is the scope of register variables?

The block they are declared in.