Skip to main content Accessibility help
Internet Explorer 11 is being discontinued by Microsoft in August 2021. If you have difficulties viewing the site on Internet Explorer 11 we recommend using a different browser such as Microsoft Edge, Google Chrome, Apple Safari or Mozilla Firefox.

Chapter 2: Fundamentals

Chapter 2: Fundamentals

pp. 23-70

Authors

, Vidyalankar Institute of Technology
  • Add bookmark
  • Cite
  • Share

Summary

Overview

C++ is an extension of C. This means that all the features of C are also available in C++. Furthermore, C++ has certain additional features of object-oriented programming, which makes it superior to the conventional C language. The details of object orientation and other features of C++ are covered in the later chapters of this text book.

In this chapter, we will study some fundamentals, which build the foundation to understand the advanced features of C and various object-oriented features supported by C++.

The First C/C++ Program

Recall from Chapter 1 that every C/C++ program has to be compiled and linked so as to convert the high-level language into the machine code. All the instructions written in the program are executed one-by-one by the processor in a sequence as they appear in the program file. Therefore, it is the job of the programmer to inform the processor about the exact starting point from which the execution of the program should begin. The main() function in C/C++ is used to represent the start and end points of the program execution. Hence, every program must have exactly one main() function, which is shown in Figure 2.1.

CPU will execute all the instructions where we write inside the body of the main()function in a sequence as they appear. The presence of empty round parenthesis after a special word main() informs the compiler that the function main() does not take any arguments. By default, every function in C/C++ is expected to return a value to the one who invokes the function. We can use a keyword void if we do not want to return any value to the calling function. The complete details of functions with arguments and return values are discussed in Chapter 7 of this text book and hence the details about ‘function arguments’ and ‘return types’ can be ignored at this point of time.

At this stage, we need to understand that a main() function is to be created using a template shown in Figure 2.1.

About the book

Access options

Review the options below to login to check your access.

Purchase options

eTextbook
US$110.00
Paperback
US$110.00

Have an access code?

To redeem an access code, please log in with your personal login.

If you believe you should have access to this content, please contact your institutional librarian or consult our FAQ page for further information about accessing our content.

Also available to purchase from these educational ebook suppliers