Monday 26 August 2013

Lecture 159

Lecture 159
//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void display(char*);  // Prototype
main ()
{

  char name[]={"Shahid"};
  display(name);
  getch();
  return 0;
}
void display(char name[])
{
  cout<<"Your name is : ";
  int i=0;
  while(name[i] != '\0')    
  {
        cout<<name[i];
        i++;
  }     
}

Output:

Lecture 158

Lecture 158

//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
int f(int);  // Prototype
int g(int);
main ()
{
  int x,y,s=2;
  s*=3;
  y=f(s);
  x=g(s);
  cout<<"\n "<<s<<y<<x;
  getch();
  return 0;
}
int t=8;
int f(int a)
{
  a+=-5;
  t-=4;
  return a+t;
}
int g(int a)
{
  a=1;
  t+=a;
  return a+t;
}


Output:

Lecture 157

Lecture 157
//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
int i=0;
void Val();  // Prototype
main ()
{
  cout <<"\n Main's i : "<<i;     
  i++;
  Val();
  cout <<"\n Main's i : "<<i;     
  Val();
  getch();
  return 0;
}
void Val()
{
  i=100;
  cout <<"\n Val's i : "<<i;     
  i++;
}


Output:

Lecture 156

Lecture 156

//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void Extern();  // Prototype
int x=21;
void display();  // Prototype
main ()
{
  int x=20;
  cout <<"\n Variable Local x : "<<x;     
  display();
  Extern();
  getch();
  return 0;
}
void Extern()
{
  cout <<"\n Variable Global : "<<x;  
  extern int x;
  x=23;
  cout <<"\n Variable external : "<<x;

}
void display()
{
  cout <<"\n Variable Global : "<<x;  
}

Output:

Lecture 155

Lecture 155

//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void Register();
void increment();
void increment1();  // Prototype
main ()
{
  Register();
  increment();
  increment();
  increment1();
  increment1();
  getch();
  return 0;
}
void Register()
{
  register int i;
   for(i=1;i<6;i++)
       cout <<"\n Register i : "<<i;

}
void increment()
{
    auto int i=1;
    cout <<"\n increment in auto i : "<<i;
    i=i+1;  
}
void increment1()
{
    static int i=1;
    cout <<"\n increment in static i : "<<i;
    i=i+1;  
}


Output:

Lecture 154

Lecture 154
//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void Auto();
void Auto1();// Prototype
main ()
{
  Auto();
  getch();
  return 0;
}
void Auto()
{
  auto int i,j;
  cout <<"\n  i : "<<i<<"  j : "<<j;
  Auto1();
}
void Auto1()
{
  auto int i=1;
   {
        cout <<"\n  i : "<<i;    
         auto int i=2;
        {
          cout <<"\n  i : "<<i;    
          auto int i=3;
            {
               cout <<"\n  i : "<<i;    
            }
        }
   }
}
Output: