Computer Science, asked by StutiDey, 1 year ago

in what way static declaration different from dynamic declaration


StutiDey: class 10

Answers

Answered by Sac10
37
An allocation of a memory is known as variable, means we use variable to store the value.

The variable are of 2types:-

1.)Static - when variable can't change its value during run time (when program is in running mode means when output window is open) is static variable. In Static variable value assigned directly in a program itself.

E.g.

int a=313;

2.)Dynamic - when variable can change its value during run time (when program is in running mode means when output window is open) is dynamic variable. In dynamic variable value assigned/taken from the user.

E.g.

int a;

cout<<”enter the value of a”;

cin>>a;

Answered by tejaskhokale05
3

Ans-Dynamic and Static Variables in C

Variable declarations can be outside all functions or inside a function

Declarations outside all functions are global and in fixed memory locationsThe static declaration declares a variable outside a function to be a “file global” (cannot be referenced by code in other source files)

Declarations within a block statement {} (function body or block statement nested within a function body):Are dynamically allocated, unless declared staticAre allocated memory when program execution enters the blockMemory is released when execution exits the blockIf a function calls itself (directly or indirectly), it gets a new set of dynamic variables (called a stack frame)This is handled no differently from any other call to the function

Similar questions