Lesson 01: Hello World

Create Your First C/C++ Console Program

Objective

  • Learn how to create a console project in Visual C++ or C++Builder IDE

Software Requirement

  • Visual C++ 2017 or newer edition
  • Or C++ Builder 10.3.x or newer edition
  • Or XCode in Mac OS X system

Background Information

There are two types of C/C++ compilers, each of which has advantages and disadvantages:

  1. Command-line C compilers
  2. IDE (Integrated Development Environment) or Windows C/C++ compilers

Command-Line C Compilers

If you use a command-line C compiler to compile and execute a C program, you have to go through the following steps:

  1. Write the C code in a text editor or word processor.
  2. Save the file as myfile.c file in your C project folder.
  3. Compile the code to a computer-executable program by entering a compiler command at a command prompt, or console window.
    For GUN C compiler: gcc -Wall -o myfile myfile.c
    For Microsoft Visual C++ command-line compiler: cl myfile.c
    For C++Builder compiler: bcc32 myfile.c
  4. Execute the program by entering
    myfile
    at the command prompt. Then you should see the program's results on the screen.

You can use any text editor or code editor that you prefer using with the command-line C compiler. Here are some useful text editors that most programmers are like:

IDE C/C++ Compilers

An Integrated Development Environment, or IDE for short, is an application or software that programmers use. It helps a programmer program easily by providing all the comprehensive facilities required for software development. IDE can improve a programmer's or developer's productivity because of its fast setup and various tools. Without this, a programmer takes a lot of time deciding on various tools for their tasks.

Mainly, an IDE includes 3 parts: source code editor, build automation tool (compiler), and debugger. The source code editor is something where programmers can write the code. In contrast, the programmers use the build automation tool to compile the codes, and the debugger is used to test or debug the program to resolve any errors in the code. Furthermore, these IDEs also come with additional features like object and data modeling, unit testing, source code library, and more.

Currently, several IDEs are available for various programming languages like Python, C++, and Java. JavaScript, R, and others. Modern IDEs even possess intelligent code completion to maximize the programmer's productivity.

IDE C compilers have the advantages:
  • The IDE compilers usually have a built-in code editor colorized for C/C++. That means the C/C++ keywords are in one color (like blue), text in text strings may be in another color (like red), comments may be in green, while other text is in black. And if you misspell a keyword in C/C++ or miss a quotation mark, this becomes immediately obvious.
  • It takes less time and effort. It includes various tools and features that help prevent mistakes, organize resources, and provide shortcuts.
  • It allows quick navigation to the type.
  • Programmers can quickly navigate to other members by using hyperlinks.
  • IDEs organize imports and can add appropriate imports.
  • It can give a warning in case of any errors or mistakes.
  • IDEs are great for generating or completing the code depending on previous codes.
  • These environments make the unit tests run easily.
Disadvantages of IDE C/C++ compilers are:
  • Commercial IDE C/C++ compilers cost money.
  • Usually, you must install it on your own computer, and require more disk space to install the software.
  • Using a command-line compiler is much faster than an IDE.
  • In UNIX/Linux computer system, you can not operate the IDE over the telnet interface.

Lab Experiment

Now, you will learn how to create a new project for a Windows console application in the IDE

Run the code and capture the screen. Paste it to your report.

 

 


Extra Useful Information for You!

 

© 2024 Air Supply Information Center (Air Supply BBS)