C/C++ after Pascal

Introduction

This is the start of a new section to help you to apply your knowledge of Pascal when learning C and C++. C++ extends the capabilities of C, so that C code should compile with a C++ compiler. We advise you to try C first, so in this tutorial the sections on C++ follow those on C.

C is more difficult than Pascal, but the transition from Pascal to C is manageable. You should be comfortable with handling pointers in Pascal before attempting C. We advise you to learn C# before C if you have the time so that learning C will be even less challenging. It is easy to find guidance on C, but be aware that much of this is intended for professionals rather than school students.

When you try a new language you will be looking out for features such as the following. Follow the links to the relevant sections of the comparison table for Pascal and C. We plan to add further links as the tutorial develops.

The next page shows a comparison table, giving the C equivalents of fragments of Pascal code.

Compiling the Demonstration Code

See Getting Started with Code::Blocks for advice on (1) downloading the free IDE, (2) installing it on Windows and on the Debian Linux operating system of a Raspberry Pi and (3) using it for the first time. If you only need to compile a few short programs you can try the inbuilt gcc compiler without an IDE as follows.

Windows on a PC

Open the Command Prompt and change directory to that containing your C source file. The instruction g++ main.c -o my_prog will compile the C source file named main.c to an executable named my_prog.exe. Execute it with the command my_prog.

Debian Linux on a Raspberry Pi

Open the LXTerminal on the Raspberry Pi and change directory to that containing your C source file. The instruction g++ main.c -o my_prog will compile the C source file named main.c to an executable named my_prog. (Copy the code into an editor such as Leafpad and save it as, for example, main.c). Execute my_prog with the command ./my_prog.

Programming - a skill for life!

Pascal Programming Tutorials