To generate a random number in C you can use the snippet below.
Sample C
#include <time.h> #include <stdlib.h> srand(time(NULL)); int r = rand();
To generate a random number in C you can use the snippet below.
#include <time.h> #include <stdlib.h> srand(time(NULL)); int r = rand();
To Set / Clear and Toggle a single bit in C++ see the methods below.
Use the bitwise OR operator (|) to set a bit.
number |= 1 << x;
Use the bitwise AND operator (&) to clear a bit.
number &= ~(1 << x);
The XOR operator (^) can be used to toggle a bit.
number ^= 1 << x;
To check if a file exists in C++ you can use the following snippet.
#include <sys/stat.h> inline bool fileExists (const std::string& fileName) { struct stat buff; return (stat (fileName.c_str(), &buff) == 0); }
To get the char code in C++ you can use the following snippet.
Simply cast the Char to int.
cout << (int)'A' << endl;