i didn't got .. !! please explain some more..
On 2/7/12, sumit mahamuni sumit143smail...@gmail.com wrote:
Hello,
Here you are right about variable p in add function that it retains it's
value even though function loses its scope. And for main function error you
are seeing has nothing to do
i think guys are confuse between scope of variable and lifetime of
variable.
p scope is add function and lifetime of p is till the program run.
so u can't access variable outside the scope of variable whatever is the
lifetime of variable.
u can look at peter ven den linden Deep C secrets.
best
I think rahul has given a clear solution i.e why the static variable is not
accessible in main() function because of its scope.
I would like to add one more point in this...that Static variables may be
initialized in their declarations;
however, the initializers must be constant expressions, and
@all
thanx for the explanation..
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
i have a confusion in it
#include stdio.h
#include stdlib.h
void add(int,int);
int main(int argc, char *argv[])
{
add(6,3);
printf(%d,p);
system(PAUSE);
return 0;
}
void add(int a, int b)
{
static int p;
p = a+ b;
}
here the memory layout says variable p is in BSS segment ... so
I think you are right about p being in BSS segment and it does last even
the function finishes, however, you may need a pointer to get the data out
of p. Then you can read the data.
Correct me if i am wrong
On Mon, Feb 6, 2012 at 1:04 PM, Ravi Ranjan ravi.cool2...@gmail.com wrote:
i have a
http://www.geeksforgeeks.org/archives/14268
On Tue, Feb 7, 2012 at 1:06 AM, gmagog...@gmail.com gmagog...@gmail.comwrote:
I think you are right about p being in BSS segment and it does last even
the function finishes, however, you may need a pointer to get the data out
of p. Then you can read
Hello,
Here you are right about variable p in add function that it retains it's
value even though function loses its scope. And for main function error you
are seeing has nothing to do with how that variable is stored?
It is about the scope of that variable C compiler sees the scope of static