answersLogoWhite

0


Best Answer

Only if you pass a pointer to it, eg:

void sub (int *into)

{

*into= 3;

}

int main (void)

{

int myvariable;

sub (&myvariable);

return 0;

}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: In c How do you access variable declared in main in other function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why all variables are declared with in the function?

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.


What is the difference between global variable and extern variable?

Global variables are non-local variables. That is, variables that are not defined in a function or class. They are globally accessible to all code in the same translation unit. External variables are global variables that have external linkage; they are accessible across translation units.


Is a public function accessed like a non-member function?

A public function is scoped to the class in which it is declared. If declared non-static, then it must be invoked against an instance of the class but if declared static then namespace resolution is required to access the function. A non-member function is not scoped to any class but may be scoped to a namespace. If no namespace is specified, then it is scoped to the (unnamed) global namespace. If scoped to any other namespace then namespace resolution is required to access the function.


What is the scope of any variable?

The Scope of a variable defines the areas of a program where this variable would be visible and can be used. For ex: a. Method variables - are visible only inside the method where they are declared and hence their scope is only the method b. Class variables - are visible inside the class and can be used by any method inside the class and hence their scope is the whole class.


What is the difference between friend function and normal member function?

We can access a Friend function from any other class in which friend function is introduced or declared even if the other class is not a member of first class. But when we use normal member function, we can have its access only in the derived classes of the first class. This is the basic difference between a friend function and a normal member function.


Which is the keyword used to access the variable declared as global variable in another file?

To be able to access a variable declared in one file/class from another file/class you need to declare that variable as "public". Doing this is a very bad coding practice because exposing a variable of a class to be available publicly to other classes is totally against the Java object oriented concepts of Encapsulation and Data hiding. So, preferably you shouldn't be doing this. However, a better way to do this is, declare the variable as private and have public accessor methods through which you can access this variable. This will ensure that your data is protected even if it is available outside the class


What are the friend function implications on information hiding?

Other than that the friend has privileged access to the private members of the class in which it is declared a friend, there are no implications. However, there has to a be a reason for the friend to require that access.


What is a zero of a quadratic function?

The "zero" or "root" of such a function - or of any other function - is the answer to the question: "What value must the variable 'x' have, to let the function have a value of zero?" Or any other variable, depending how the function is defined.


What does In public mean?

The keyword public is an access specifier. A variable or a method that is declared public is publicly accessible to any member of the project. Any class or method can freely access other public methods and variables of another class.


What is the result of substituting a value for a variable in a function?

To find the value of the other variable


When can we say that a function is a relation?

When it doesn't fulfill the requirements of a function. A function must have EXACTLY ONE value of one of the variables (the "dependent variable") for every value of the other variable or variables (the "independent variable").


When can we say that a relation is a function?

When it doesn't fulfill the requirements of a function. A function must have EXACTLY ONE value of one of the variables (the "dependent variable") for every value of the other variable or variables (the "independent variable").