Difference between revisions of "Intermediate C++ Game Programming Tutorial 1"
(→Homework) |
(→Homework) |
||
Line 28: | Line 28: | ||
# In Microsoft Visual C++, what is the size in bytes of the following data types: <code>int</code>, <code>char</code>, <code>double</code>, <code>unsigned int</code>, <code>short</code>, <code>bool</code> | # In Microsoft Visual C++, what is the size in bytes of the following data types: <code>int</code>, <code>char</code>, <code>double</code>, <code>unsigned int</code>, <code>short</code>, <code>bool</code> | ||
<div class="mw-collapsed mw-collapsible" style="width:450px"> | <div class="mw-collapsed mw-collapsible" style="width:450px"> | ||
− | <code>int</code>: 4 | + | <code>int</code>: 4<br /> |
+ | <code>char</code>: 1<br /> | ||
+ | <code>double</code>: 8<br /> | ||
+ | <code>unsigned int</code>: 4<br /> | ||
+ | <code>bool</code>: 1 | ||
</div> | </div> | ||
# Make the following conversions: 01000111b -> dec, 11001111b -> hex, 10h -> dec, 7Ah -> bin, 193d -> bin | # Make the following conversions: 01000111b -> dec, 11001111b -> hex, 10h -> dec, 7Ah -> bin, 193d -> bin | ||
<div class="mw-collapsed mw-collapsible" style="width:450px"> | <div class="mw-collapsed mw-collapsible" style="width:450px"> | ||
− | 01000111b -> dec: 71 | + | 01000111b -> dec: 71<br /> |
+ | 11001111b -> hex: CF<br /> | ||
+ | 10h -> dec: 16<br /> | ||
+ | 7Ah -> bin: 01111010<br /> | ||
+ | 193d -> bin: 11000001<br /> | ||
</div> | </div> | ||
Revision as of 23:56, 4 May 2017
We've been using int
s and float
s and bool
s this whole time, but have you ever wondered about a day in the life of a variable? In this video, we find that shit out, and so much more. We also learn about the cousins of int
and float
, adding to our arsenal basic data types we can use. What's the endgame you ask? This stuff is gonna help us understand pointers and strings, and it's just interesting shit.
Contents
Topics Covered
- The concept of memory (RAM)
- Binary and hexadecimal number systems
-
char
,short
,long long
,double
-
unsigned
integral types - The ranges and sizes of basic data types
- Layout of variables in memory
- Correspondence between C++ code and CPU operations
Video Timestamp Index
Bonus Video: Red Pill [Memory and Data]
The description of how variable are organized in memory in Tutorial 1 is a simplified model that will help us understand memory and pointers; it is not 100% accurate.
Chili had originally planned to teach the full details of how variables are allocated, explaining things like storage classes (stack, heap, static), the details of stack management and function stack frames, and exploration of the memory and machine instructions using the debugger. But then he realized that this amount of detail and complexity might be too much of a mind fuck for too many people, so he cut that content from Tutorial 1.
Since the video is already recorded, it will be released as optional content for people who are interested in the nitty-gritty details, but the keyword here is optional; you are not required to know this content to continue on with the tutorials and it will not be referred to in the mainline tutorial series.
Video link: Red Pill [Memory and Data]
Homework
This lessons homework is to answer the following questions. When you think you have the answer, click "expand" to reveal the correct answer.
- In Microsoft Visual C++, what is the size in bytes of the following data types:
int
,char
,double
,unsigned int
,short
,bool
int
: 4
char
: 1
double
: 8
unsigned int
: 4
bool
: 1
- Make the following conversions: 01000111b -> dec, 11001111b -> hex, 10h -> dec, 7Ah -> bin, 193d -> bin
01000111b -> dec: 71
11001111b -> hex: CF
10h -> dec: 16
7Ah -> bin: 01111010
193d -> bin: 11000001