Size Allocated for Types And Dynamic Programming.If the size allocated for type 'int' is 2^32. How will numbers higher than that | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

12th Jan 2018, 2:56 PM
Justine Ogaraku
Justine Ogaraku - avatar
14 Answers
+ 13
Yes please. 😀
12th Jan 2018, 4:08 PM
Justine Ogaraku
Justine Ogaraku - avatar
+ 12
Thanks alot.
12th Jan 2018, 4:52 PM
Justine Ogaraku
Justine Ogaraku - avatar
+ 12
Thanks @Ozren
13th Jan 2018, 7:06 PM
Justine Ogaraku
Justine Ogaraku - avatar
+ 12
Thank you AZTECCO, they were of great help to me.
15th Jan 2018, 8:04 PM
Justine Ogaraku
Justine Ogaraku - avatar
+ 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
12th Jan 2018, 4:13 PM
Ipang
+ 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.
15th Jan 2018, 10:27 AM
AZTECCO
AZTECCO - avatar
15th Jan 2018, 10:30 AM
AZTECCO
AZTECCO - avatar
+ 10
https://code.sololearn.com/cc3TJ7N9HLZX/?ref=app https://code.sololearn.com/cEKyFrZcJHe7/?ref=app
15th Jan 2018, 10:38 AM
AZTECCO
AZTECCO - avatar
+ 8
really nice to help you! :)
15th Jan 2018, 10:01 PM
AZTECCO
AZTECCO - avatar
+ 5
dynamic programming and dynamic memory allocation are two different things
12th Jan 2018, 3:33 PM
code learner
code learner - avatar
+ 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.)
13th Jan 2018, 8:03 AM
---
--- - avatar
+ 3
how can I help you about dynamic programming?
12th Jan 2018, 3:08 PM
code learner
code learner - avatar
+ 2
for higher numbers you must change data type
12th Jan 2018, 3:06 PM
code learner
code learner - avatar
+ 2
shall I post example of dynamically allocated integer array
12th Jan 2018, 4:00 PM
code learner
code learner - avatar