August 1st, 2003, 12:03 AM
some doubts in c
1)can i use nested function in c. it is working with
how many nesting possible
2)Why nonstatic function can't access ststic varibale in c++ ?
3) where will static varibale will stored in memmory
August 1st, 2003, 12:39 AM
all i can add is that static variables are stored in the heap.
August 1st, 2003, 12:44 AM
not very sure
static varibale r stored in heap
i aslo think so But i went for an interview
and the interviwer told me it is not correct and it stored in data
area can you get exact picture
August 1st, 2003, 12:53 AM
2) How do you explain the results of this program?
using namespace std;
static int objectCount;
name = n;
int Person::objectCount = 0;
Last edited by 7stud; August 1st, 2003 at 01:00 AM.
August 1st, 2003, 12:54 AM
August 1st, 2003, 01:01 AM
August 1st, 2003, 01:12 AM
hello i want to know c implementation
August 1st, 2003, 01:15 AM
non static function in the case of c++
only static varibale can be access in static function
and i doubt why this implementation
August 1st, 2003, 01:18 AM
can u tell answers to my other questions
August 1st, 2003, 03:40 AM
August 1st, 2003, 03:58 AM
I herad it is in some data area. Ok can you explain in c++ why
nostatic function can't access static variable??
And what about function nesting ???
can you explain it
August 1st, 2003, 07:53 AM
I think that is because,"The static methods cannot refer to the non-static data members of the class because values for those only exist for instances of the class. "
August 1st, 2003, 08:43 AM
c doesn't allow nested functions at all, in any way at all so far as i know. if you're using nested functions then you're not using c i don't think.
the gnu compiler can compile c and c++ so i'm going to guess it's compiling your code that you're referring to as c as c++.
not sure, but code that uses nested functions can't correctly be described as c.
? :/ there's 2 types of static - internal and external. internal is only applicable to variables, whereas external is applicable to both functions and variables.
internal static (or internal non static - doesn't make any difference) variables can only be accessed from within the function where it resides. the scope of internal variables is limited to the function they're in. static, or not stitic, in conjunction with internal variables doesn't make any difference to the scope (scope as in, what can access them (or what can see them), and what can't.)
(making an internal variable static effects it's lifetime (not scope), as in it lasts from when the function it's in is first called to when the whole code ends, where as internal non-static variables only last so long as that particular single function call lasts - normal / usual 'automatic' variables basically)
external variables, and functions can both have static applied to them. functions are always external - there can't be an internal function (so far as c goes). if an external variable or a function is static then this limits their scope to the file they're in.
obviously functions usually have a very global nature to them - they can be accessed pretty much from anywhere in the code, but making them static restricts that globalness - restricts their scope. and the same goes for global variables - static global (external) variables are no longer global - it removes their global nature; their scope is restricted to the file they're defined in.
i think that's how it is but i'm not *totally* 100% sure but i think it is. so far as where on the heap or stack they're stored i'm not sure. also this is all from a c point-of-view. some of it may also be applicable to c++, but there again it may not be.
Last edited by balance; August 1st, 2003 at 10:10 AM.