Posts

Showing posts from September, 2022

Tokens in C++: Strings

Image
  WHAT ARE STRINGS?          Strings are a special type of character array, where all the data is stored in a continuous memory locations. At this stage of discussions, we will introduce the the concepts of strings, but in later discussion, we will present a much more elaborate concept of strings. Strings can be demonstrated as an array of characters, as seen in the diagram below:                     In this scenario, we can clearly see that when the word "Hello!"  is added to the program is added, an array of 7 bits, each able to hold a character, is created. When strings are allocated, these contiguous memory spaces are filled with data. Finally, an additional memory space is kept to add a null character to signify the end of a string.          Strings are characterized be characters which are encapsulated inside double quotes ("") . This is the limit to which w...

Tokens in C++: Constants

Image
  WHAT ARE CONSTANTS?          Constants  are a special type of variables, whose values can be assigned only during development, while at runtime, they are treated as non-editable pieces of code. In other words, constants are variables which are set as read-only, thus preventing corruption and unrequired editing and changes. The following illustration demonstrates a variable encapsulated into a constant .          As demonstrated by the illustration, there are two independent ways of converting a variable into a constant, by declaring variables using #define  or by using the const  keyword alongside variable declaration. Refer to the code below to understand both the methods.  By using #define #define PI 3.14   In this case, we have added the value of π, which is 3.14. This value is constant, and we do not want to change it anytime during the runtime. Hence we have declared the value itself, ensuring da...

Tokens in C++: Identifiers

Image
  WHAT ARE IDENTIFIERS?         Identifiers  are C++ tokens which refer to the names of variables, functions, arrays, classes, objects, etc. These tokens are completely user-specific. As the name suggests, identifiers  assist the compiler in 'identifying' the different instances of keywords, such as data-types, classes and functions. The following diagram demonstrates the concept of identifiers in further detail.            As evident from the diagram above, we have a C++ program which uses the capabilities of various predefined and user-defined keywords. Here, int , float , class  are predefined keywords, while OwnClass  is a user-defined keyword, derived from a pre-existing user-defined class. Now, the program isn't able to utilize the fundamental characteristics of the keywords directly, and thus representatives of these keywords are created in the program. These representatives, shown with dark-green rec...

Tokens in C++: Keywords

Image
  WHAT ARE KEYWORDS?     Keywords  are tokens which hold special meaning to the compiler. This means that these words cannot be used to name variables, functions and methods. Keywords stand for a special purpose, and they command the compiler to take action, such as create variables of a certain type, utilize memory capabilities, create structured data, etc.      The keywords being used in C++ are as follows: asm:  The asm  keyword is used to declare that a block of code is to be passed to the assembler. auto:   auto  is a storage class specifier that is primarily used to define objects in a code block. break: The break  keyword terminates a switch statement or a loop.  case: The case  keyword is used specifically within a switch statement to specify a match for the statement's expression. catch: The catch  keyword specifies actions when an exception occurs. char:   char is a fundamental data type, which def...

Getting started with C++ Programming

Image
INTRODUCTION     Though writing programs in C++ is simple, a few things are essential for initiating the development of applications using C++. The basic requirements are: Word Editor: A word editor is an application that allows creating or editing documents. We require an editor to write the actual content of the program. Compiler: A compiler is a computer program which converts a program written in a high-level language to computer-understandable code. In the case of C++, we require the GNU GCC Compiler. More information about GNU GCC Compiler can be read from  here .     In the modern context of industrial-grade programming, we utilize a specialized application called Integrated Development Environment   (IDE) . IDEs incorporate both the components of Word Editor and Compiler under the same roof, which eases the development process.      In the case of C++ development, there are major IDEs which work towards making industrial-grade program...

Introduction to C++

Image
INTRODUCTION           C++ is a major programming language in the global programming sphere. It is an improvement of the vastly popular programming language, C. The language was developed by Bjarne Stroustrup in 1983, and was developed with the intentions of providing advanced data protection, access control and modular reusability.  FEATURES OF C++      C++  is an advanced programming language, which incorporates the best of previous languages, and presents us with a very capable language which has been able to create a major paradigm shift in the programming mentality of the industry. The language incorporates the following major features:- Statically typed:  C++ is a statically typed language, which means that programming applications using C++ requires using static declarations, as well as utilization of keywords, identifiers and blocks. In other words, these programming languages require  variable types to be known at...