C and C++

Difference between break and continue statement

Break Continue can be used in switch statement cannot be used in switch statement causes premature exit of the loop causes skipping of the statements following it in the body of the loop The control is transferred to the statement of the loop control is transferred back to the loop The loop may not complete […]

Data Structures

Recursion

Recursion is the name given for expressing anything in terms of itself. A function which contains a call to itself or call to another function ,which eventually causes the first function to be called,is known as a recursive function.  Recursive procedures generally solve a given problem by reducing the problem to an instance of the […]

Data Structures

Evaluation of Postfix Expression

1.read only one input symbol at a time from postfix expression. 2.if input symbol is operand ,push operand in to stack(before pushing convert that into integer). 3.if input symbol is operator ,pop two operands from stack perform operation and push result into stack. 4.repeat the process till the expression become empty. 5.finally result will be […]

Data Structures

Convert infix expression into postfix Expression

Infix notation: In most common arithmetic opeartions,the opeartor is placed b/w the two operands. 1) A+B 2)C-D 3) E*F 4) G/H 5)(a+b)*c It is called infix notation,it can be parantheised or parantheses free expressions. Polish /Prefix notation: It is named after the polish mathematician Jan Lukasiewicz,refers to the notation in which the operator symbol is […]

Data Structures

Implement Stack by using dynamic arrays

When a stack is implemented by using static arrays the size of the stack is bound to MAXSTK(i.e maximum elements a stack can have)but some time stack need be dynamic. This can be achieved by using dynamic arrays The memory for the stack is dynamically allocated by using memory allocation functions such as malloc or […]

Data Structures

Explain Stack

It is a linear data structure or ordered collection of elements where the elements are processed in last in first out manner(LIFO). In stack insertion and deletions are made at one end i.e top Stack can be implemented by using array or linked list Operations on stacks. Special terminology is used for two basic operations […]

C and C++

Explain Constructors

Constructors are special class functions which performs initialization of every object. The Compiler calls the Constructor whenever an object is created. Constructor’s initialize values to data members after storage is allocated to the object. While defining a constructor you must remember that the name of constructor will be same as the name of the class, […]

C and C++

Explain Namespace

Namespace is a new concept introduced by the ANSI C++ standards committee. A namespace is introduced to avoid name clashes (global name conflicts) like re-declaration of variables, method names, class, and structure names. Syntax for using standard namespace: using namespace std; In the above syntax “std” is the namespace where ANSI C++ standard class libraries […]

C and C++

Explain function overloading with example

Function overloading means, two or more functions have the same names but different argument lists The arguments may differ in the type of arguments or number of arguments, or both. However, the return types of overloaded methods can be the same or different is called function overloading. Function overloading concepts helps us to use the […]

C and C++

C++ program to swap two integers values and display the values before and after swapping using call by reference

#include<iostream> using namespace std; void swap(int &x, int &y) { int temp; temp = x; x = y; y = temp; } int main() { int a, b; cout<<“Enter the value of a: “; cin>>a; cout<<“Enter the value of b: “; cin>>b; cout<<endl<<“Before swapping: “; cout<<“a= “<<a<<” and b= “<<b; swap(a, b); cout<<endl<<“After swapping: “; […]