OCaml - Variable - Creating variables

For creating variables in OCaml we need to use the let keyword.

The syntax to create a variable is the following:

 

# let myVar = 90;;

When you type enter, it will be displayed the type of your variable:

 

OCaml - Utilities - Using the rlwrap command

When you use OCaml on Linux for example, you cannot by default using the arrow from your keyboard, neither the completion.
If you try to use them you will have something like that:

# ^[[A^[[D^[[C^[[B^[[D^[[A^[[C^[[D^[[B^[[C

But there is readline wrapper named rlwrap that will help us in this task!

UNIX & GNU/Linux - System calls - Using time()

It is sometimes useful to display the current date in your terminal.
For that the time() system call function is the best one.
Let's see an example within this tiny tutorial of C programming language:

C++ - Tips'n Tricks - Converting a std:string into an int and converting an int to a std::string

For the C, we had the famous atoi() function, but for C++, how can I convert a std::string into an int?

C++ - Keyword - virtual

The virtual keyword is used in different ways in C++.

The most common way to use it is before a destructor.
Indeed, with this virtual keyword we can specified that the children of a class will be deleted before its parent.

Let's see it with a tutorial.

C++ - Makefile - Adding flags

A personal Makefile is sometimes better than a Makefile generated by default by your IDE, such Eclipse or Visual Studio C++ for example.

C++ - Errors / Warnings - After compiling

As the same for the C - Error / Warning section, I made this one to summarize common mistakes when I tried to compile my code.

So let's go to see some good errors and warnings in C++ (I'm sure it is also a great moment for you when you discovered these errors).

C - Errors / Warnings - After compiling

Errors and warnings generally encountered by a coder during his hard life of coder will be added here, in this special section.

I will not make difference between errors and warnings, because I always compile with CFLAGS such as -Wall -Werror -Wextra and thus warnings are treated as errors.

C - Recursion - Classical recursion of a factorial

A classical example of recursions is of course the factorial one.

If you want to know the result of a factorial, do not hesitate to use a recursive function.

Let's see it:

C - Recursion - Finding a number until a variable reaches another one

The code below display the nb variable until it reaches the number ten.

But the recursion will display the phrase in the printf(), of the main(), at the end of the while inside the r() function.

Pages

Subscribe to BadproG.com RSS