Some notes about C++

C was language created in the 60's as a systems language. It could do low-level work or be a high-level language. It was compiled as most languages were in those days. It had very few safety checks in it, like not accessing a string or list outside its bounds.

In 1979 Bjarne Stroustrup wrote a compiled language first called "C with Classes", later C++. It incorporated some of the later thinking about object-oriented programming and several safety checks. It's used for programming at different levels.

One of the major differences between C++ and Python is "strongly typed" versus "weakly typed". C++ requires that you declare your variables before you use them, stating what type they are. This is the type they retain their whole lifetime. There are ways to convert data from one type to another, typecasts are available. Python allows variables to be switched from one type to another with just an assignment statements.

Functions written in Python can be virtually independent of the type of parameters. C++ is much more disciplined; every function must know what type of parameters it will have when it is compiled.

Programs written in Python tend to be 3-10 times shorter than C++ (or Java) programs written for the same purpose. Python is faster to develop in, especially for prototypes of a program. Some programmers develop a program first in Python and then translate it to C++ in order to get the benefits of compilation into machine code.

Of course Python programs will run more slowly than C++ programs because Python involves translating every statement before executing it; C++ programs have been converted to pure machine code. At run time they need no translation at all.

Another difference between Python and C++ which is caused by the fact that one is interpreted and one is compiled is the ordering of function definitions in a file. C++ requires that a definition of a function be seen by the compiler before the call to that function is seen. Python only requires that a definition of a function be seen before the call to the function is executed. Example:

definition of funA
definition of funB
definition of main
   call to funB
   call to funA
works in both languages.
definition of funA
definition of main
   call to funB
   call to funA
definition of funB
call to main
would work in Python, would not work in C++.

Math operators in C++ are similar to the ones in Python. It does not have exponentiation (**) or floor division (//). It does have / and %, although the / operator does give a result that depends for its type on the types of the operands. It does have +=, -=, etc. but also ++ and -- which came from C. The last two were the equivalent of machine language instructions in the machine where C was developed, so they were very quick to translate and very economical in terms of the RAM taken up by the instruction.

Formatting of code in C++ is much less structured than in Python. Indentation is encouraged but not required. Braces are used to mark off blocks of code where Python uses indentation. Python was created with the goal of attractive, easy to read programs which display their structure visually.

C++ and Python have pretty similar data types. Both have bools, both have ints and floats. Python handles strings more flexibly than C++ and Python has many more functions and methods for manipulating strings than C++ does. Python is also more flexible and powerful at handling large numbers than C++.

C++ has been used for decades for writing all kinds of systems programming (operating systems, utilities, applications of all kinds), computation intensive tasks, embedded software. It has a wide range of tool kits and libraries available, both open source and commercial. There are implementations of the compiler and associated utilities like editors and debuggers that are free (GNU gcc, cygwin, etc.) and commercial (Microsoft, Sun). Python is a newer language (1991) which is still gaining ground in the programming language market. Python is used a lot for writing web applications, scripts of all kinds, automation tools.

If a software company implements an application, they are more likely to distribute JUST the executable (binary) file to their customers. It will run faster and be much harder to reverse engineer. Python applications usually are the source code and require the customers to have a Python interpreter on their machines, although there are a few Python compilers available.

Both C++ and Python are object-oriented. You can write your own classes and make your own objects. C++ is closer to the "pure" idea of OOP, Python allows some variations on the model. See the idea of "private variables" for an example.

Examples:
GCD program Python
GCD program C++
Function order Python
Function order C++

reference Transition from Python to C++ PDF

Dev C++ free, open source IDE for C++ for Windows