Memory Allocation for Object

Generally in C language, when we create a normal variable, a space is allocated to the variable to store value. The memory space is common to save and change. Only one copy of the variable is available in memory and the same copy is shared between all the functions in a program. But in case of Object in C++ language, scenario is some thing different then the normal variable declaration. The member functions are created and placed in the memory space only once when they are defined as part of…

Read More

Inline Function in C++

What is inline function? An inline function is a function that is expanded in line when it is invoked. Inline expansion makes a program run faster because the overhead of a function call and return is eliminated. It is defined by using key word “inline”. To eliminate the cost of calls to small functions C++ proposes a new feature called inline function. An inline function is a function that is expanded inline when it is invoked .That is the compiler replaces the function call with the corresponding function code. syntax:…

Read More

Sequential Control Statements

A statement ensures that the instructions(or statements) are executed in the same order in which they appear in the program. By default system executes the statements in the program in sequential order. These statements does not include use of any condition or any expression to transfer control flow to another part of the program. It will execute all the statements in same order as they are appear in the program. Example: here, in above example no any use of condition to transfer the flow of control. it will be executed…

Read More

Control Statements in C++

Usually a program is not a linear sequence of instructions. It may repeat code or take decisions for a given path-goal relation. Most programming languages have control flow statements (constructs) which provide some sort of control structures that serve to specify order to what has to be done to perform our program that allow variations in this sequential order.The flow of execution of statements in a program is called as control. Control statement is a statement which controls flow of execution of the program. Control statements are classified into following…

Read More

Why variable cannot be used without specifying its type in C++ ?

C++ is a statically typed language. Hence, any variable cannot be used without specifying its type. This is why the type figures in the declaration. This way the compiler can protect you from trying to store a value of an incompatible type into a variable, e.g. storing a string in an integer variable. Declaring variables before use also allows spelling errors to be easily detected. Consider a variable used in many statements, but misspelled in one of them. Without declarations, the compiler would silently assume that the misspelled variable actually…

Read More

Data types in C++

A data type is used to indicate the type of data value stored in a variable. All C compilers support a variety of data types. This variety of data types allows the programmer to select the type appropriate to the needs of the application as well as the machine. With the exception of void the basic datatypes may have several modifiers receding them to serve the needs of various situations. The modifiers signed, unsigned, long and short may applied to character and integer basic data types. ANSI C supports the…

Read More

Manipulators

Manipulators are used to manage the output stream and to modify the user output. Different manipulators are used to set different output formats. Manipulators are operator that are used to format the data display. The most commonly manipulators are endl and setw. To use various manipulators in C++ program <iomanip.h> header file is compulsory to include. List of Manipulators endl setw setfill internal setprecision showpoint fixed scientific endl – endline manipulator The endl manipulator, when used in an output statement, causes a line feed to be insert. Just like a…

Read More

Input Output Operator (<<) (>>)

The shift operators (>> and <<) have been overloaded so you can perform I/O operations on istream and ostream objects, most notably cout, cin, and file streams. Thus you could just do console I/O operations. In C++ input operator(>>) and output operator(<<) for console IO operations are explained below. 1. Output Operator (Insertion Operator <<) To display single line or statement on console IO window “cout<<” function is used. cout<< uses to manage output streams on console IO window. cout<< is a library function defined in <iostream.h> header file of…

Read More

Member Dereferencing Operator

In computer programming, a dereference operator, also known as an indirection operator, operates on a pointer variable. It returns the location value, or l-value in memory pointed to by the variable’s value. In the C programming language, the dereference operator is denoted with an asterisk ( * ). For example, in C, we can declare a variable M that holds an integer value, and a variable *ptr that holds a pointer to an integer value in memory: In C++ Programming we have three different dereferencing operators. Pointer to a member…

Read More

Scope Resolution Operator ( :: )

Visibility or availability of a variable in a program is called as scope. There are two types of scope in c++ programs. Local scope Global scope Local scope: visibility of a variable is local to the function in which it is declared. Global scope: visibility of a variable to all functions of a program. Scope resolution operator in “::” is used to access global variables if same variables are declared as local and global. Block2 contained in block l .Note that declaration in an inner block hides a declaration of…

Read More