Once a class is defined, it can be used to create variables of its type known as objects. The relation between an object and a class is the same as that of a variable and its data type. [Read more…] about How to Creating Objects and Allocate Memory for Objects in c++
c++ – Defining member functions inside or outside the class definition
Member functions of a class can be defined either outside the class definition or inside the class definition. In both the cases, the function body remains the same, however, the function header is different. [Read more…] about c++ – Defining member functions inside or outside the class definition
What is Class in C++
A class in C++ is a user-defined data type that binds data and the functions that operate on the data together in a single unit. Like other user-defined data types, it also needs to be defined before using its objects in the program. A class definition specifies a new data type that can be treated as a built-in data type. [Read more…] about What is Class in C++
Function Overloading
In some cases when a similar action is to be performed on different types of data, different functions having different names are to be defined for all types of data. This makes the program very complex as the programmer must keep a track of the names of all the functions defined in the program. To prevent such situations, C++ allows the functions to be overloaded. [Read more…] about Function Overloading
A program to demonstrate the concept of returning a reference
A program to demonstrate the concept of functions returning values
Static Variables Within Functions in C ++
Any value assigned to an automatic variable within a function is lost once the control returns from the called function to the calling function. However, there may be a situation where the value of the local variable needs to be preserved even after the execution of the function gets over. This need can be fulfilled by declaring the variable as static. A static variable is commonly used when it is necessary for a function to remember a value between its calls. To understand the concept of static variables, consider this example. [Read more…] about Static Variables Within Functions in C ++
Arguments to main () in C ++
Like C, C++ enables to pass arguments to the main () function also. These arguments are passed by typing them after the program name on the command line. Hence, these arguments are known as command line arguments. Command line arguments help in providing data to the program. [Read more…] about Arguments to main () in C ++
C++ function Call by Reference
In addition to call by value, a function can also be called by reference. C++ provides two ways of passing arguments as reference to a function. The arguments can be passed either as a reference type or as a pointer type. [Read more…] about C++ function Call by Reference
C++ function call by value
When a function is called by value, the values of the actual arguments are copied into the formal arguments and the function works with these copied values. As a result, any changes made to the copied value in the called function do not affect the value of the actual argument in the calling function. [Read more…] about C++ function call by value
Invoking Functions in C++
In order to use a function in different parts of a program, the function must be called or invoked by another function. In C++, functions are called by specifying the name of the function, followed by the parentheses. The parentheses mayor may not contain a list of arguments depending on the function definition. [Read more…] about Invoking Functions in C++
Definition of Function in C++
In order to use a function in a program, the function must be first defined somewhere in a program. A function definition contains the code that specifies the actions to be performed. The syntax for defining a function is [Read more…] about Definition of Function in C++
What is Function Declarations or Function Prototype?
Like variables, functions also need to be declared before they are used in programs. A function declaration is also known as function prototype. Function prototype is a model or a blueprint for a function that informs the C++ compiler about the return type, the function name, and the number and data type of the arguments passed to the function. Function name together with parameter list is known as function signature and it does not include return type of a function. The syntax for declaring a function is [Read more…] about What is Function Declarations or Function Prototype?
How to Declaring Array of Structures in c++
An array of structures refers to an array in which each element is of structure type. To declare an array of structures, firstly, a structure is defined and then an array of that structure is declared. The syntax for declaring an array of structures is [Read more…] about How to Declaring Array of Structures in c++
How to Declaring Nested Structures in c++
Like other user defined data types, a structure can also include another structure, as its member, in its definition. A structure defined within another structure is known as a nested structure. [Read more…] about How to Declaring Nested Structures in c++
How to Declaring and Accessing Structure Variables in c++
A structure can be used in a program only if memory is allocated to it. The structure definition informs the compiler about the type and the number of data members in the structures. However, it does not allocate any memory for the structure. To use a structure in a program efficiently, a structure variable needs to be declared. The syntax for declaring a structure variable is [Read more…] about How to Declaring and Accessing Structure Variables in c++
Defining Structures in C++
Like arrays, structures are also used to store a list of data items in a single variable. However, these data items may be of different data types. Structures are used whenever a programmer requires binding the same or different types of related data items together into a single entity. [Read more…] about Defining Structures in C++
Multi-Dimensional Arrays in c++
Multi-dimensional arrays can be described as ‘arrays of arrays’, that is, each element of the array is itself an array. A multi-dimensional array of dimension n is a collection of items that are accessed with the help of n subscript values. [Read more…] about Multi-Dimensional Arrays in c++
Single-Dimensional Arrays in c++
A single-dimensional array is the simplest form of an array that requires only one subscript to access an array element. Like an ordinary variable, an array must have been declared before it is used in the program. The syntax for declaring a single-dimensional array is [Read more…] about Single-Dimensional Arrays in c++
Difference between Structures and Unions
Both the structures and unions are syntactically and functionally same, however, they differ in the way memory is allocated to their members. While declaring structure variables, the different members are stored in different, although, adjacent memory locations whereas different members of a union variable share the same memory location. The amount of memory sufficient to hold the largest member of a union is allocated to a union variable. Thus, a union enables the same block of memory to store variable of one type at one time and of different type at another time. To understand the concept of memory allocation to a union, consider these statements. [Read more…] about Difference between Structures and Unions
Jump Statements in c++ or Goto statement
Jump statements are used to alter the flow of control unconditionally. That is, jump statements transfer the program control within a function unconditionally. The jump statements defined in C++ are break, continue, goto and return. In addition to these jump statements, a standard library function exit () is used to jump out of an entire program. [Read more…] about Jump Statements in c++ or Goto statement
Iteration Statements or Loops in C++
The statements that cause a set of statements to be executed repeatedly either for a specific number of times or until some condition is satisfied are known as iteration statements. That is, as long as the condition evaluates to True, the set of statement(s) is executed. The various iteration statements used in C++ are for loop, while loop and do while loop. [Read more…] about Iteration Statements or Loops in C++
Conditional Statements in C++ or if Statements
Conditional statements, also known as selection statements, are used to make decisions based on a given condition. If the condition evaluates to True, a set of statements is executed, otherwise another set of statements is executed. [Read more…] about Conditional Statements in C++ or if Statements
What is Operators? Explain Scope Resolution Operator and Operators Precedence.
In addition to the operators like arithmetic operators, relational operators, logical operators, the conditional operator and assignment operators that most of the languages support, C++ provides various new operators that are given in Table. [Read more…] about What is Operators? Explain Scope Resolution Operator and Operators Precedence.
What is Expressions in C++?
A combination of variables, constants and operators that represents a computation forms an expression. Depending upon the type of operands involved in an expression or the result obtained after evaluating expression, there are different categories of an expression. These categories of an expression are discussed here. [Read more…] about What is Expressions in C++?
Data Types – Explain Data Type in C++.
A data type determines the type and the operations that can be performed on the data. C++ provides various data types and each data type is represented differently within the computer’s memory. The various data types provided by C++ are built-in data types, derived data types and user-defined data types as shown in Figure. [Read more…] about Data Types – Explain Data Type in C++.
Input/Output Operator in C++
In C++, input and output (I/O) operators are used to take input and display output. The operator used for taking the input is known as the extraction or get from operator (>>), while the operator used for displaying the output is known as the insertion or put to operator (<<). [Read more…] about Input/Output Operator in C++
Structure of a C+ + Program
Programs are a sequence of instructions or statements. These statements form the structure of a C++ program. C++ program structure is divided into various sections, namely, headers, class definition, member functions definitions and main function. [Read more…] about Structure of a C+ + Program
Explain Various Type Object-Oriented Languages. Advantages and Applications of OOP
To develop software, the object-oriented concepts need to be implemented in any high-level language. The high-level language that implements the concepts of object-oriented programming is known as an object-oriented language (also called an OO language). In general, an object-oriented language must support all or some of these OO concepts. [Read more…] about Explain Various Type Object-Oriented Languages. Advantages and Applications of OOP
What is Polymorphism?
Polymorphism (a Greek word meaning having multiple forms) is the ability of an entity such as a function or a message to be processed in more than one form. It can also be defined as the property of an object belonging to a same or different class to respond to the same message or function in a different way. For example, if a message change_gear is passed to all the vehicles then the automobiles will respond to the message appropriately however, the pulled vehicles will not respond. The concept of polymorphism plays an important role in OOP as it allows an entity to be represented in various forms. [Read more…] about What is Polymorphism?