http://www.geeksforgeeks.org/archives/14268
On Tue, Feb 7, 2012 at 1:06 AM, [email protected] <[email protected]>wrote: > 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 <[email protected]>wrote: > >> 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 its an >> independent region from stack frame..... when the function looses its scope >> from function defination(add) then still it should be alive... and can be >> recognized/used by other function(main).... but it gves an error of unknown >> variable "p"..... need the correct logic....... if i m wrong... >> >> thanx >> ravi >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
