- You cannot cast between integer and boolean values.
However it is trivia to convert data between integer and boolean.
For example,
int i = b ? 1 : 0;
convert a boolean valueb
into an integer valuei
, andboolean b = i != 0
convert an integer valuei
into a boolean value …
String in Different Programming Languages
A string is essentially a sequence of characters. This is how string is implemented in many programming languages (string in Java is different). For this reason, you can operate string like an array in some programming languages. This post is a shallow summary on strings in different programming languages. For …
Automated Phone Bill Using Ruby Program
I have decided to try different programming languages. I learn Python a month ago. I would like to say that Python is great scripting language. The only thing I do not like so far is inconsistent about methods and functions. It is annoying to remember whether a call should be …
Java Programming Style
Good Writing Style
-
It is recommend to always use
{}
if even there is only one statement inside it. The reason is that you never know whether you are going to add more statements into it or not. And it will make the code more readable. -
Feel free to declare the …
Pointers in C++
Pointers
-
No pointer, no polymorphism.
-
C/C++ is notorious for raw pointers. While pointers can boost up the speed of programs, it invites a trillion chances for making mistakes. You should avoid using raw pointers, instead, consider using
unique_ptr
,shared_ptr
andweak_ptr
. They are almost as efficient as raw pointers …
Write Portable C++ Code
-
Addresses on 64 and 32 OS are different, so you have to be careful when your program have to deal with address. For example, if you take the difference of two pointers/iterators, you should type
std::ptrdiff_t
(which is essentially a singed integer type). Using an arbitrary integer type …