+ 18
Size Allocated for Types And Dynamic Programming.If the size allocated for type 'int' is 2^32. How will numbers higher than that
be stored?? Because : #include <iostream> using namespace std; int main(){ int num = 4294967296; cout<<num<<endl; } Displays 0 to the screen. Does this kind of situation call for 'long long's type?? And also, please I need someone to give a deep explanation on Dynamic Programming. How does the memory allocated change during the course of the program change, since the size allocated for 'int' type in the Stack and on the Heap are 4bytes respectively. Edit: Sorry, Dynamic Memory Allocation
14 ответов
+ 13
Yes please. 😀
+ 12
Thanks alot.
+ 12
Thanks @Ozren
+ 12
Thank you AZTECCO, they were of great help to me.
+ 10
@Justin, these links may help understand why that int doesn't hold the value you assigned to it, it's about data type ranges, you can read about it here:
https://msdn.microsoft.com/en-us/library/s3f49ktz.aspx
https://en.m.wikipedia.org/wiki/C_data_types
I wrote a code related with data type ranges out of curiosity, but some may say I'm doing it wrong, because mostly would suggest to use limits header, but I'm doing manual calculation. Note that in this code, data ranges are only available for integer family.
Hth, cmiiw
https://code.sololearn.com/c4yCTSdke9iV/?ref=app
+ 10
Hello dear Justine!
Dynamic memory is one of the most complex and powerful features of c++.
The management of this feature is all in your hands, so.. you got a great power but also a great responsibility.
From my little experience I feel to suggest you to use classes to manage the way you manage memory. that way you should use all the powerful features of OOP and easily track down issues.
+ 10
I give you some of my experiments..
hope it helps!
https://code.sololearn.com/cuwoDWJQGImG/?ref=app
https://code.sololearn.com/cqG8b8XZtwc2/?ref=app
+ 10
https://code.sololearn.com/cc3TJ7N9HLZX/?ref=app
https://code.sololearn.com/cEKyFrZcJHe7/?ref=app
+ 8
really nice to help you! :)
+ 5
dynamic programming and dynamic memory allocation are two different things
+ 4
For your integer size problem either do
auto num = 4294967296; //(modern way / let compiler decide which type)
or make a typedef to let the user know which size the type should have, something like
typedef long long int64;
int64 num = 4294967296; //(standard way).
Your question about dynamic mem alloc is too broad, but the basic idea has become to use the memory header and the pointers defined in it (unique/shared etc.)
+ 3
how can I help you about dynamic programming?
+ 2
for higher numbers you must change data type
+ 2
shall I post example of dynamically allocated integer array