what is the diff b/w static and non static variables in C.
Give some examples plz.
Answer Posted / 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 |
Post New Answer View All Answers
How can this be legal c?
What does s c mean in text?
What is the use of extern in c?
disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit
What is difference between class and structure?
The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference
If i have an array 0 to 99 i.e,(Size 100) I place the values 1 to 100 randomly like a[0]=29,a[1]=56 upto array[99].. the values are only between 1 to 100. getting the array values by using scanf.. If i entered one wrong element value line a[56]=108. how can i find it.. and also how to find the missing value in 1 to 100.. and i want to replace the missing values.. any one of them know please post your answer..
what is the structure pointer?
Why does everyone say not to use gets?
How can you pass an array to a function by value?
Explain bitwise shift operators?
Why & is used in c?
Write an algorithm for implementing insertion and deletion operations in a singly linked list using arrays ?
What is difference between constant pointer and constant variable?
Why is void main used?