#include <iostream>
#include <cstdint> // int32_t etc
int main()
{
// we discussed integer types
// remember that an unsigned integer can store 0 to (2^bits)-1
int a; // different platforms will have different standard # bits for int
unsigned int b; // non-negative only
int32_t c; // this will be 32 bits for sure
uint32_t d; // unsigned... non-negative numbers only
int64_t e; // it is pretty hard to overflow a 64 bit integer
// bytes can be "encoded" to mean a character...
// e.g. "A" in ascii is 01000001 or 41 in hex..0100 is 4, 0001 is 1
// While the "ascii" encoding only goes up to 127, utf-8 encoding
// can go beyond this by using certain bytes as "hints" that the
// character is encoded with multiple bytes... hence foreign alphabets
// and emojis are possible. We will focus on ascii for the near future.
int8_t s[7] = "hi mom"; // automatically includes a trailing null character
printf("%s\n", s);
printf("%.*s\n",3,s); // to print just the first 3 characters
char s2[15] = {'a','r','r','a','y','\0'}; // char is the same as int8_t
printf("%s\n",s2);
// Note that in C++ double quotes are used for a literal describing an array
// of characters, while single quotes are used for a single character.
// We discussed that std::cout << a << b << std::endl; will risk
// outputing a and b at slightly different times, so that if some
// other thread of execution is writing to the same stream at the
// same time there is the opportunity for messages to get strangly
// interleaved. The printf() family of functions does not have this
// problem.
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: