473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Staic array de allocation

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

Jul 31 '07 #1
7 1757
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;
}

Jul 31 '07 #2
somenath wrote:
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.

Jul 31 '07 #3
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.
--
Flash Gordon
Jul 31 '07 #4
Little guy wrote:
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
Jul 31 '07 #5
santosh <sa*********@gmail.comwrote:
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.

--
C. Benson Manica | I appreciate all corrections, polite or otherwise.
cbmanica(at)gmail.com |
----------------------| I do not currently read any posts posted through
sdf.lonestar.org | Google groups, due to rampant unchecked spam.
Aug 2 '07 #6
On Thu, 2 Aug 2007 15:58:48 +0000 (UTC), Christopher Benson-Manica
<at***@faeroes.freeshell.orgwrote:
>santosh <sa*********@gmail.comwrote:
>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.
Why is that a misconception? When Google fails to deliver posts for
days, "broken" seems a fair description.

--
Al Balmer
Sun City, AZ
Aug 2 '07 #7
Al Balmer <al******@att.netwrote:
On Thu, 2 Aug 2007 15:58:48 +0000 (UTC), Christopher Benson-Manica
<at***@faeroes.freeshell.orgwrote: (without appropriate care)
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.
"...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.

--
C. Benson Manica | I appreciate all corrections, polite or otherwise.
cbmanica(at)gmail.com |
----------------------| I do not currently read any posts posted through
sdf.lonestar.org | Google groups, due to rampant unchecked spam.
Aug 2 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: pvinodhkumar | last post by:
The number of elemets of the array, the array bound must be constant expression?Why is this restriction? Vinodh
4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
14
by: Gattaca | last post by:
I would like to create a matrix of integers by allocating memory dynamically (malloc or calloc) because i and j are defined during execution of the program. I have got not problem to do this in...
7
by: kaul | last post by:
i want to create a 2-d array containg r rows and c columns by dynamic memory allocation in a single statement so that i will be able to access the ith and jth index as say arr how is that...
11
by: D | last post by:
hi, i would like to know how to calculate the size of a dynamic array created using a dereference declaration like int *numbers and allocating via malloc or calloc: numbers=(int...
7
by: Sam | last post by:
Hello I have a structure called Company. struct Company { char *employee; char *employee_address; }; I want to build an array of this structure but the number of employees will change...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
4
by: somenath | last post by:
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...
3
by: aeo3 | last post by:
Hi All, Now, I am trying to build a project, I need to expand an array of pointer to classes. Moreover, this array includes some elements I want to delete them. So, I create another array, copy the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.