473,395 Members | 1,537 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,395 software developers and data experts.

size of C++ function stack

1
I have a question on the below piece of code:
void func()
{
int *px1 ;

if(..)
{
int x1;
px1= &x1
}

cout << *px1 ;
}
In the above piece of code, the scope of variable x1 is the if-block but if i store the pointer of x1 to a different variable ( px1 ) and access it later then will it cause a problem.
1. The variable x1 will be allocated on the function stack but when x1 goes out of the scope then is the memory associated to it returned to the free pool.
2. Is the size of function stack fixed in C++ or does it vary as variables are created and destroyed.
thanks
Amit
May 27 '08 #1
2 2132
gpraghuram
1,275 Expert 1GB
I have a question on the below piece of code:
void func()
{
int *px1 ;

if(..)
{
int x1;
px1= &x1
}

cout << *px1 ;
}
In the above piece of code, the scope of variable x1 is the if-block but if i store the pointer of x1 to a different variable ( px1 ) and access it later then will it cause a problem.
1. The variable x1 will be allocated on the function stack but when x1 goes out of the scope then is the memory associated to it returned to the free pool.
2. Is the size of function stack fixed in C++ or does it vary as variables are created and destroyed.
thanks
Amit
The memory you are trying to use is an invalid memory and sure it will create problem
I dont have much idea about the function stack size

raghu
May 27 '08 #2
Ganon11
3,652 Expert 2GB
In C at least (and on an Intel processor), the stack grows and shrinks within your function. So C code of 'int x1' might be interpreted as the computer adding 4 bytes to the stack (thus 'allocating' 4 bytes of memory for x1).
May 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: dati_remo | last post by:
Hi, is it possible to find the dimension of an array using a pointer? main() { int a; f(a); return; }
2
by: ronjon | last post by:
I am trying to corelate C code and its associated assembly code produced by gcc. In particular,I am trying to figure out how the stack pointer increments during variable initialization inside a...
4
by: ivan | last post by:
Hi, How can we calculate the stack and heap size requried by a C program. Is there any specific formula used? Please suggest. regards, Ivan
13
by: Ben R. Bolton | last post by:
The documentation indicates that the threads "default stack size" is 1MB. The work "default" implies that it can be changed. Is it possible to change the StackSize in .NET? If so how? Is it...
5
by: sunny | last post by:
Hi All Is there any way to determine stack and heap size, during runtime. i.e can we predict stack overflow. etc
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.