Auto variables in different blocks in C

void main() { int p=100; clrscr(); printf("\n P=%d",p); { int p=50; printf("\n P=%d",p); } { int p=40; printf("\n P=%d",p); } printf("\n P=%d",p); } Output P=100 P=50 P=40 P=100 In the above program, the declaration of ‘p’ is made at three places with different values. In the first block, the value of ‘p’ is 100 and […]
Continue reading…

Enjoyed this post? Share it!

 
 

Automatic Variables in C

auto variables are defined inside a function. A variable declared inside the function without storage class name is, by default, an auto variable. These functions are declared on the stack. The stack provides temporary storage. The scope of the variables is local to the block in which they are defined. These variables are available only […]
Continue reading…

Enjoyed this post? Share it!

 
 

Stack implementation with operator overloading in C++

#include <conio.h> #include <iostream.h> #include <dos.h> #include <stdio.h> #include <conio.h>   int top=0;   //class definition   class stack { public: int a[]; int n;   stack (); stack operator << (int); stack operator + (int); stack operator –(void); }r;   //definig the constructor to initialize   stack :: stack () { clrscr(); cout <<"Enter […]
Continue reading…

Enjoyed this post? Share it!

 
 

Quicksort of array in c++

#include <iostream.h> #include <conio.h> #define SIZE 10   template <class T> class QSORT { private: T Array[SIZE]; int len; public: QSORT(int); //constructor void getArray(void); void quickSort(int,int); int partition(int, int); void printArray(void); }; //End of QSORT class   template <class T> QSORT <T> :: QSORT(int length) { len = length;   //Initialize all array elements to […]
Continue reading…

Enjoyed this post? Share it!

 
 

Operations on Linked Lists in C++

#include <iostream.h> #include <conio.h>   class listNode { public: int data; listNode *ptr; };   class linkedList { private: listNode *head;   public: linkedList() //constructor { head = NULL; } void insertFront(void); int deleteFront(void); void showList(void);   ~linkedList() //destructor { delete head; } }; //End of linkedList   void linkedList::insertFront(void) { listNode *newNode; int item; […]
Continue reading…

Enjoyed this post? Share it!

 
 

Add two complex objects and add real part to a complex object in C++

#include <iostream.h> #include <conio.h>   class COMPLEX { private: int realp; int imgp; public: void readValues(void) { cout<<"Enter the real part and imaginary part"<<endl; cin>>realp>>imgp; }   friend COMPLEX ADD(COMPLEX,COMPLEX); friend COMPLEX ADD(int,COMPLEX); friend ostream& operator << (ostream&, COMPLEX&); };   COMPLEX ADD(COMPLEX s1, COMPLEX s2) //To add two COMPLEX objects { COMPLEX c; c.realp […]
Continue reading…

Enjoyed this post? Share it!