what is the diff b/w static and non static variables in C.
Give some examples plz.
Answers were Sorted based on User's Feedback
Answer / anil kumar
Static variables are used for internal contextual
communication purpose.
non static variables are not used for contextual
communication
for that please go through the below code:
static int i=10;
int main()
{
int x=20;
Printf(“%d %d”,x, i);
Fun();
return 0;
}
Void Fun()
{
Printf(“%d”, i);
}
In the above code “i” is the static variable and “x “is the
local variable
Is This Answer Correct ? | 22 Yes | 7 No |
Answer / parth ujenia
main()
{
int i=5;
while(i!=0)
{
printf("%d",i--);
main();
}
getch();
}
output: 54321
Is This Answer Correct ? | 7 Yes | 1 No |
Answer / vignesh1988i
when we have declared a variable as static...... we cant
initilize it again....... the meaning of static storage
class is for only one time initilization.... whenever the
compailer come accross the same static keyword ,... the
present value in that variable will get printed as the
compailer ignores the line static.........
eg:::::
#include<stdio.h>
#include<conio.h>
void main()
{
for(int i=0;i<3;i++)
{
static int p=1;
printf("%d ",p);
p++;
}
output will be:: 1 2 3
since the compailer ignores the static int p=1 after it
initilizs once...... and one more thing.. when we refer
variable p after the loop structure it will give an error
that::: "UNDEFINED SYMBOL 'P'" ,because the scope of this
static is only under the block and not ourtside.....
non static :: it is called as automatic storage class.... in
programs we would have given as;;
int a; or char sd; etc...
these inside the compailer treated as automatic storage
class..... the scope of this storage class is only undere
the block... after comming out it dies......
eg:::::::
#include<stdio.h>
#include<conio.h>
void main()
{
int a=12;
{
a=90;
printf("%d",a);
}
printf("%d",a);
}
the output will be::::::: 90 12.... because of the above
mentioned scope.....
i think you can clearely understand the concept....... if
you didnt understand ... send mail to me.. we can
discuss.... softvig_88@yahoo.com...
thank you
Is This Answer Correct ? | 6 Yes | 4 No |
write a program in 'c' to find the value of p[i+1]^n.p,i,n are arguments of a macro and n is a integer
What are type modifiers in c?
Why pointers are used?
Result of the following program is main() { int i=0; for(i=0;i<20;i++) { switch(i) case 0:i+=5; case 1:i+=2; case 5:i+=5; default i+=4; break;} printf("%d,",i); } } a)0,5,9,13,17 b)5,9,13,17 c)12,17,22 d)16,21 e)syntax error
change to postfix a/(b+c*d-e)
what is linkage error when it occurs in c program
Explain how many levels deep can include files be nested?
How can I invoke another program from within a C program?
HOW DO YOU HANDLE EXCEPTIONS IN C?
What are the difference between a free-standing and a hosted environment?
How can I access memory located at a certain address?
p*=(++q)++*--p when p=q=1 while(q<=6)