Re: [algogeeks] C concept on memory layout

2012-02-07 Thread Manni mbd
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

Re: [algogeeks] C concept on memory layout

2012-02-07 Thread rahul
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

Re: [algogeeks] C concept on memory layout

2012-02-07 Thread Atul Singh
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

Re: [algogeeks] C concept on memory layout

2012-02-07 Thread Ravi Ranjan
@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

[algogeeks] C concept on memory layout

2012-02-06 Thread Ravi Ranjan
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

Re: [algogeeks] C concept on memory layout

2012-02-06 Thread gmagog...@gmail.com
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

Re: [algogeeks] C concept on memory layout

2012-02-06 Thread atul anand
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

Re: [algogeeks] C concept on memory layout

2012-02-06 Thread sumit mahamuni
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