answersLogoWhite

0


Best Answer

If you declare a variable inside of any fuction (except main) it will not be available to other functions.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: In c plus plus are local declarations visible to the function in a program?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is local declaration?

Declarations inside a function is called local declaration


Explain the structure of c program with an suitable example?

Basic structure of a C program is /* Documentation section */ /* Link section */ /* Definition section */ /* Global declaretion section */ /* Function section */ (return type) (function name) (arguments...) void main() { Declaration part Executable part (statements) } /* Sub-program section */ (return type) (function name 1) (arguments...) (return type) (function name 2) (arguments...) . . . (return type) (function name n) (arguments...) Basic structure of a C program is /* Documentation section */ /* Link section */ /* Definition section */ /* Global declaretion section */ /* Function section */ (return type) (function name) (arguments...) void main() { Declaration part Executable part (statements) } /* Sub-program section */ (return type) (function name 1) (arguments...) (return type) (function name 2) (arguments...) . . . (return type) (function name n) (arguments...)


What is the purpose of the program stack?

Its main use is to store local variables, arguments and return address each time a function is called.When your program calls a function the following happen :- The function arguments are put on the stack- The current instruction pointer is put on the stack- The program jumps to the start of the function- Space is allocated on the stack to hold local variables- The function executes- The space holding local variables is de-allocated- The instruction pointer is restored and removed from the stack (we are now leaving the function and resuming the calling procedure)- The arguments are removed from the stack


What is the difference between local variable and global variable in Embedded C?

It's simple. A global variable has a scope through out out the C program. It can be accessed anywhere from any function or etc. A local variable on the other hand, is local to it's container only and can not be accessed outside of it's container. For example a function has variable sum then sum is only accessible within the function and not anywhere else.


What is the lifetime of local variables in a function?

If the variable is local to the function it exists until the function returns.

Related questions

What is local declaration?

Declarations inside a function is called local declaration


Explain the structure of c program with an suitable example?

Basic structure of a C program is /* Documentation section */ /* Link section */ /* Definition section */ /* Global declaretion section */ /* Function section */ (return type) (function name) (arguments...) void main() { Declaration part Executable part (statements) } /* Sub-program section */ (return type) (function name 1) (arguments...) (return type) (function name 2) (arguments...) . . . (return type) (function name n) (arguments...) Basic structure of a C program is /* Documentation section */ /* Link section */ /* Definition section */ /* Global declaretion section */ /* Function section */ (return type) (function name) (arguments...) void main() { Declaration part Executable part (statements) } /* Sub-program section */ (return type) (function name 1) (arguments...) (return type) (function name 2) (arguments...) . . . (return type) (function name n) (arguments...)


What is the purpose of the program stack?

Its main use is to store local variables, arguments and return address each time a function is called.When your program calls a function the following happen :- The function arguments are put on the stack- The current instruction pointer is put on the stack- The program jumps to the start of the function- Space is allocated on the stack to hold local variables- The function executes- The space holding local variables is de-allocated- The instruction pointer is restored and removed from the stack (we are now leaving the function and resuming the calling procedure)- The arguments are removed from the stack


Why is returning a pointer to a local variable a logical error?

Local variables automatically fall from scope when a function returns. If the function returns a pointer to one of its local variables and you subsequently attempt to dereference that pointer, you introduce undefined behaviour into your program. With undefined behaviour you have no way of knowing what will happen: the program may work; the program may crash; the program may wipe the user's hard-drive. Anything can happen when you introduce undefined behaviour into a 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.


What is the difference between local variable and global variable in Embedded C?

It's simple. A global variable has a scope through out out the C program. It can be accessed anywhere from any function or etc. A local variable on the other hand, is local to it's container only and can not be accessed outside of it's container. For example a function has variable sum then sum is only accessible within the function and not anywhere else.


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 is the lifetime of local variables in a function?

If the variable is local to the function it exists until the function returns.


How do you declare a function only if undeclared anywhere else even if the somewhere else is a file included after?

Your question makes no sense, but here is a simple rule: Public functions' declarations should be in a header file, local (or static) functions' declaration at the beginning of the source file.


What is difference between Static and Global variable?

Static may be local of global -local static variable is limited to the function scope. and retain it's value when function is been called . compiler differentiate static variables with a prefix function name while dealing with same name static variable in different functions. - Global static variable is visible to all the function defined in the file and retain it value but it cannot be used outside this file. now Global Variable --- this variable is also visible to all of the functions inside the file but also can be used outside the file via extern keyword.


What are local variables and global variables?

Local variables: These variables only exist inside the specific function that creates them. They are unknown to other functions and to the main program. As such, they are normally implemented using a stack. Local variables cease to exist once the function that created them is completed. They are recreated each time a function is executed or called. Global variables: These variables can be accessed (ie known) by any function comprising the program. They are implemented by associating memory locations with variable names. They do not get recreated if the function is recalled.


What will be the prototype of a user defined function?

In C programming, there are no built-in functions; all functions are user-defined. In order to use a function it must first be declared. This can be achieved by importing the header file containing the declaration (via the #include compiler directive) or by typing the declaration by hand. The definition (implementation) of a function is not required in order to use a function, but if a function is used it has to be defined somewhere (undefined functions will cause a link error). Where a function is used by several translation units, placing the declaration in a header file ensures the declaration is consistent across all translation units. Grouping declarations by purpose allows us to import several declarations at once. Declarations that are not used are simply ignored. A declaration informs the compiler of the function's name and type, and the number and type of its arguments, if any. This describes the interface to the function. A function's type is denoted by its return type. A function that has no return value is simply declared void (no type). The return type always comes first in a declaration, followed by the function name, which must be a unique identifier within the scope in which it is declared (global or local scope). A local name will mask a global name, effectively hiding it from the local scope. Function arguments (the formal arguments of the function) are delimited by parenthesis after the function name. A single argument of type void denotes no arguments while multiple argument types must be separated by commas (void types are not permitted in a multiple argument function). The complete declaration is terminated by a semi-colon immediately after the closing parenthesis. If the declaration is also a definition, the function body (the implementation) replaces the closing semi-colon. To assist with documentation, the formal arguments of a declaration may be named (unless the argument is void). However, where names are given, they need not match the corresponding names provided by a function's definition, where defined separately. Using longer descriptive names in the declaration helps document their purpose, while the definition can use shorter names that are easier to work with.