Staic array de allocation

S

somenath

Hi ALL,

I have a doubt regarding declaration of static variable.
Suppose if we declare a char array as static then when the memory
reserved for the elements of the array will be de allocated .For
example when the memory reserved for "array[10]" will be de
allocated ?


#include<stdio.h>
char *return_static();
int main(void)
{
char *received = NULL;
received = return_static();
printf("\n Contain of array = %s\n",received);
return 0;
}
char *return_static()
{
static char array[10]={"hello"};
return array;
}

Regards,
Somenath
 
L

Little guy

lan collins is right,static member will be deallocated when app
exit,refer below example:
#include <stdio.h>

class CTest
{
public: CTest(){ printf("allocate!\n");}
~CTest(){ printf("deallocate!\n");}
void dosomething(){ printf("do something!\n"); }
};


CTest& return_static();

int main(int argc, char* argv[])
{
CTest& t= return_static();
t.dosomething();
return 0;
}


CTest& return_static()
{
static CTest t;
return t;
}
 
S

santosh

somenath said:
Hi ALL,

I have a doubt regarding declaration of static variable.
Suppose if we declare a char array as static then when the memory
reserved for the elements of the array will be de allocated .For
example when the memory reserved for "array[10]" will be de
allocated ?

You asked this question a while ago and got answers. If you're posting
through Google Groups, it's recommended to wait for a few hours, for your
post, and any replies to it, to show up, before attempting reposting. The
latency of the Google Groups interface is much more than traditional Usenet
access.
 
F

Flash Gordon

Little guy wrote, On 31/07/07 09:03:
lan collins is right,static member will be deallocated when app
exit,refer below example:
#include <stdio.h>

class CTest
{
public: CTest(){ printf("allocate!\n");}

<snip>

Why are you posting C++ to a C group? It is not topical and not relevant
to what goes on with C.
 
D

Default User

Little said:
lan collins is right,static member will be deallocated when app
exit,refer below example:
#include <stdio.h>

class CTest
{
public: CTest(){ printf("allocate!\n");}
~CTest(){ printf("deallocate!\n");}
void dosomething(){ printf("do something!\n"); }
};


You are confused as to which newsgroup you are reading. This is not a
C++ group.





Brian
 
C

Christopher Benson-Manica

santosh said:
You asked this question a while ago and got answers. If you're posting
through Google Groups, it's recommended to wait for a few hours, for your
post, and any replies to it, to show up, before attempting reposting. The
latency of the Google Groups interface is much more than traditional Usenet
access.

It can possibly be up to a few days, based on some accounts I seem to
recall. Unfortunately it often chances that posts show up
immediately, leading to the misconception that something is broken
when they do not.
 
A

Al Balmer

It can possibly be up to a few days, based on some accounts I seem to
recall. Unfortunately it often chances that posts show up
immediately, leading to the misconception that something is broken
when they do not.

Why is that a misconception? When Google fails to deliver posts for
days, "broken" seems a fair description.
 
C

Christopher Benson-Manica

Al Balmer said:
On Thu, 2 Aug 2007 15:58:48 +0000 (UTC), Christopher Benson-Manica
Why is that a misconception? When Google fails to deliver posts for
days, "broken" seems a fair description.

"...leading to the misconception that the post will never show up,
when in fact it will." That's what I should have said. Thanks.

I suppose the real misconception is that using Google groups
effectively is easy and reliable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top