C/C++ programming language

Certify and Increase Opportunity.
Be
Govt. Certified Software Security Professional

C/C++ Programming Language

Both C and C++ programming languages, are general purpose programming languages, which are used extensively across industry for developing high performance application, operating systems, etc

The C language was created in the early 1970s as a system implementation language for the UNIX operating system. The C Programming Language, often called “K&R” [Kernighan 1978], was originally published in 1978. Language changes around this time were largely focused on portability as a result of porting code to the Interdata 8/32 computer.

C++ programming Language
The C++ programming language has two main components: a direct mapping of hardware features provided primarily by the C subset, and zero-overhead abstractions based on those mappings. Stroustrup describes C++ as “a light-weight abstraction programming language designed for building and using efficient and elegant abstractions”; and “offering both hardware access and abstraction is the basis of C++. Doing it efficiently is what distinguishes it from other languages”.

C++ programming language inherits most of C’s syntax. The following is Bjarne Stroustrup’s version of the Hello world program that uses the C++ Standard Library stream facility to write a message to standard output:

#include <iostream>

int main() {

std::cout << “Hello, world!\n”;

}

Object storage

As in C, C++ supports four types of memory management: static storage duration objects, thread storage duration objects, automatic storage duration objects, and dynamic storage duration objects.
Static storage duration objects

Static storage duration objects are created before main() is entered (see exceptions below) and destroyed in reverse order of creation after main() exits. The exact order of creation is not specified by the standard (though there are some rules defined below) to allow implementations some freedom in how to organize their implementation. More formally, objects of this type have a lifespan that “shall last for the duration of the program”.

Static storage duration objects are initialized in two phases. First, “static initialization” is performed, and only after all static initialization is performed, “dynamic initialization” is performed. In static initialization, all objects are first initialized with zeros; after that, all objects that have a constant initialization phase are initialized with the constant expression (i.e. variables initialized with a literal or constexpr). Though it is not specified in the standard, the static initialization phase can be completed at compile time and saved in the data partition of the executable. Dynamic initialization involves all object initialization done via a constructor or function call (unless the function is marked with constexpr, in C++11). The dynamic initialization order is defined as the order of declaration within the compilation unit (i.e. the same file). No guarantees are provided about the order of initialization between compilation units.
Thread storage duration objects

Variables of this type are very similar to static storage duration objects. The main difference is the creation time is just prior to thread creation and destruction is done after the thread has been joined.
Automatic storage duration objects

The most common variable types in C++ are local variables inside a function or block, and temporary variables. The common feature about automatic variables is that they have a lifetime that is limited to the scope of the variable. They are created and potentially initialized at the point of declaration (see below for details) and destroyed in the reverse order of creation when the scope is left. This is implemented by allocation on the stack.

Local variables are created as the point of execution passes the declaration point. If the variable has a constructor or initializer this is used to define the initial state of the object. Local variables are destroyed when the local block or function that they are declared in is closed. C++ destructors for local variables are called at the end of the object lifetime, allowing a discipline for automatic resource management termed RAII, which is widely used in C++.

Member variables are created when the parent object is created. Array members are initialized from 0 to the last member of the array in order. Member variables are destroyed when the parent object is destroyed in the reverse order of creation. i.e. If the parent is an “automatic object” then it will be destroyed when it goes out of scope which triggers the destruction of all its members.

Temporary variables are created as the result of expression evaluation and are destroyed when the statement containing the expression has been fully evaluated (usually at the ; at the end of a statement).

C/C+ programming language
Certified Marketing Manager

Get industry recognized certification – Contact us

keyboard_arrow_up