Skip to main content

The C++ Way!

This post deals with definitions of few terms, understanding of which are important for having a strong foundation in C++.  This is a living blog and you can expect appends with logs at the bottom of the post.
  1. Object: Most commonly accepted definition of an object is a region of memory that has a type.
  2. Variable: A named storage that can be manipulated.
  3. Scope:
    A scope is a part of program in which a name has a particular meaning.
    '::' is the scope resolution operator used to refer to names from a different scope.

    #include<iostream>
    using namespace std;
    int variable_1 = 10;
    
    int main(){
        int variable_1 = 20;
        cout << :: variable_1 << endl;  //prints 10 on console. ::variable_name fetches the variable from global scope.
        return 0;
    }
    
  4. Lifetime:
    The lifetime of an object is the time during the programs execution that the object exists.
  5. Declaration:
    A declaration makes a name known to the program. We can declare a name without defining it by the use of extern keyword which is used to make compiler aware that the name has been defined somewhere else, may be in some other file (C++ supports separate compilation.).
    Function declaration, also known as function prototype, composes of the return type, the name and the parameter list without a function body. A name can be declared multiple times but defined only once.
  6. Definition:
     A definition creates the associated entity. Any declaration that uses an explicit initializer is a definition even if it is with keyword extern. It is an error to provide an initializer on an extern inside a function.
  7. Types:
    A type defines both the contents of a data element and the operations that are possible on those data.
  8. Manipulator:
     Manipulators are functions specifically designed to be used in conjunction with the insertion (<<) and extraction (>>) operators on stream objects, for example [1].
    They are still regular functions and can also be called as any other function using a stream object as argument, for example [2].
    Manipulators are used to change formatting parameters on streams and to insert or extract certain special characters.
    [1] cout << boolalpha;
    [2] boolalpha(cout);
  9. Initialize:
    Provide a value to the object at the time it is created.
  10. Statement:
    A part of program that specifies an action to take place when a program is executed.
  11. Declarators:
    The part of a declaration that includes the name being defined and an optional type modifier.
    In the below snippet, '&' is the declarator.
  12. int array_var[20];
    int &array_reference = array_var;
  13. Constant Reference:
    There is no way to make a reference refer to different object, in some sense all references are const. const reference is generally used as an abbreviation for "reference to const".

  14. const int variable_one = 32;
    
    const int& variable_reference_one = variable_one;   //ok
    
    int& variable_reference_two = variable_one;  //error
    

  15. Top and Low Level Constants:
    Low level constants are integral to types and cannot be ignored. Top level constants specifies that the objects may not be changed.
    int variable_one = 23;
    
    int* variable_ptr = &variable_one;
    

    Applying a top level constant on the definition of variable_ptr would mean that pointer object itself is constant that is, variable_ptr can point to only a single object variable_one as in following example:
    int* const variable_ptr = &variable_one;
    

    Low level constants can only be applied to compound types such as references and pointers, with a meaning that the object they are associated to is constant. The following example would mean that we cannot change the value of variable_one with the help of variable_ptr.
    const int* variable_ptr = &variable_one;
    

  16. Lvalues and Rvalues:
    When we use an object as use an object as an rvalue, we use the object's value (its contents). When we use an object as an lvalue, we use the object's identity (its location in the memory.)
References:
1. C++ Primer 5th Edition, Lippman - Lajoie - Moo
2. www.cplusplus.com 

Logs:
1. 14 definitions added on September 9, 2018.

Comments

  1. Wow! Important concepts put in such lucidity.
    And, I loved the idea of a live blog. Way to go!

    ReplyDelete

Post a Comment

Popular posts from this blog

Plug & Rule : An Introduction to PAM!

The Pluggable Authentication Modules (PAM) library is a generalized API for authentication related services which allows a system administrator to dynamically configure authentication schemes for all PAM-enabled system utilities and applications by adding and removing PAM modules on the running system. It's a layer between Linux applications and native underlying authentication system. PAM is implemented as shared objects or so-files, and the applications communicate with the PAM library through the PAM API. Fig. 1 : PAM Framework Traditionally, login authentication is done by comparing the encrypted password for the user in the password file (/etc/shadow), but each program that requires authentication implements its own authentication mechanisms. For example, various services like FTP, SSH, et cetera have individual ways of authenticating their users. As a result, the administrator has to spend unnecessary amount of time in maintaining the database. A PAM service module p

Understanding Firewalls and Netfilter

A Firewall is designed to prevent unauthorized outside users from accessing a network or host. It is a device (software or hardware), installed between the internal network and the Internet. Firewall performs filtering of the packets that attempt to enter or leave a network. This is done by defining various policies that enforce control over the network traffic. A Bastion Host defines a simple firewall implementation, where the bastion host is any computer that is fully exposed to attack by being on the public side of the DMZ, unprotected by a firewall or filtering router. [1] It is also referred to as the, Bastion firewall. The bastion node, is usually a very powerful server with improved security measures and custom software. A typical Bastion firewall implementation DMZ (Demilitarized Zone), also known as Perimeter Network, refers to the part of the network, that is neither private nor public. It introduces an additional layer of security, as external network has ac