Naming conventions in C++

In this tutorial, we will learn about the naming conventions in C++.

Before proceeding to the naming conventions of C++, let us understand the definition of a convention. The convention is a formal way in which one does a particular task. The naming convention is a particular way to name the various components that we use in a programming language. It is used to increase user readability and to make the source code more understandable.

The names of the programming components such as a class or variable should give a brief idea about the component. It should be relevant to the functionality of that particular component.

The naming conventions in C++

  • Class: The class name should always start with a capital letter since it is a noun. It should not contain an underscore.
  • Variable: It should not start with a number, special character, etc. It should start with an alphabet or underscore and can contain digits in it.
  • Method: It performs a particular task. So, it should contain the relevant name. For example, the method has the name even() and it finds whether a number is even or odd. It can have a prefix and suffix of certain keywords relevant to the functionality of the method. For example, the method to get a value from the user can have the name getValue(). It can have alphabets and digits in it.
  • Pointers: It is indicated by a * which prefixes the variable name of the pointer, The naming convention is similar to that of a variable.
  • The preprocessor and global variables: They should always be in capital letters when in use.

These are the few rules for the naming conventions in C++. I hope this post was helpful to learn how to use these conventions efficiently.

Thanks for reading!

Recommended Posts:
Override keyword in C++
C++ time() function with example

Leave a Reply

Your email address will not be published. Required fields are marked *