Wednesday, August 08, 2012

Program to copy one string to another string by using pointers

Program to copy one string to another string by using pointers
Copy string Output

void main(void) {
  char sta[]="Pakistan";
  char stb[15];
  char *sa=sta;
  char *sb=stb;
  while(*sa!='\0') {
  *sb=*sa;
  *sa++;
  *sb++;
  }
  *sb='\0';
  cout<<stb<<endl;
}

Program to combine two strings by using pointers


void main(void){
  char sta[]="Hello";
  char stb[]="World";
  char stc[20];
  char *s=stc;
  char *ptr=sta;
  while(*ptr!='\0'){
  *s=*ptr; *s++; *ptr++;
  }
  *s=' '; *s++; ptr=stb;
  while(*ptr!='\0'){
  *s=*ptr; *s++; *ptr++;
  }
  *s='\0';
  cout<<stc<<endl;
}

Swap two values by using pointers as arguments to a function


void swap(int *, int *);
void main(void) {
int a,b;
a=10;
b=20;
swap(&a,&b);
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
}
void swap(int *x, int *y) {
int temp;
temp=*x;
*x=*y;
*y=temp;
}

Program to input data into an array and then to print on the screen by using pointers as function arguments

Program to input data into an array and then to print on the screen by using pointers as function arguments
output

void display(int *);
void main(void) {
  int i,arr[5];
  cout<<"\nInput:\n";
  for(i=0;i<5;i++) {
  cin>>arr[i];
  }
  display(arr);
}
void display(int *ptr) {
  cout<<"\nOutput:\n";
  for(int i=0;i<5;i++) {
  cout<<*ptr<<endl;
  ptr++;
  }
}

How to download complete website each and everything

In some case you know that for some days there will be no internet available to me and there is a website which you like very much visit daily. Just internet you cannot visit? So there is offline solution you can download this website and browse offline when you have no internet facillity.

Memory distribution in Computer

Memory

             The information (instruction and data) required is stored in memory. The computer's memory is constructed out of semi-conducting material and stores information in binary form. Binary information is composed of two symbols 0 and 1, called binary digits(bits). All information within the computer is represented by two digits. The memory is organized into equal sized units (usually a collection of 8 bits, called a byte). These units are arranged a sequence and are identified by numbers called addresses. The memory of a computer can be divided into distinct parts as below.

Registers

     Registers are locations within the microprocessor where data is stored temporarily during processing.These internal high speed registers are used in arithmetic and logic operations for holding data operands. Some registers are accessible by the user through instructions.  Other s are reserved for the use of the CPU to perform it's activities.

Internal Cache

     Cache is a small high speed memory thata contains frequently used data. The use of cache avoids repeated reading of data from the slower main memory. Internal cache is located within the main microprocessor.
External Cache
    External cache is used to supplement the internal cache. It is used when an internal cache is not present.It is placed between the CPU and the main memory.
Main Memory
   Main memory stores data and instructions required by the main microprocessor. The main memory is also called RAM(Random Access Memory). Microprocessor instructions can directly access main memory locations. Main Memory is fast but expensive. However it is volatile the content stored will be lost when the power supply is cut off.
Secondary Memory
Memory levels in computer
Memory levels in computer
   All the data and programs required by the computer cannot be stored in the main memory because it is small in size and volatile. Secondary memory is slower but less expensive than main memory. It is also non-volatile and larger in size.The microprocessor can access the various types of memory in the memory hierarchy up-to the main memory. The microprocessor cannot access the secondary memory directly. Therefore, data  from the secondary memory has to be brought to the main memory so that the processor can use it.Memory management techniques are required to transfer information between the main  memory and secondary memory and this function is performed by the operating system. Some examples of secondary storage devices are hard disks, floppy disks, CD-ROM's, etc.
    The various types of memory are shown in the order of increasing size, decreasing speed and decreasing cost. Registers are the fastest memory devices but their high cost does not make it feasible to have them in large numbers. Similarly secondary memory is the least expensive but is very slow. The hierarchy therefore achieves optimal performance at reasonable costs as the amount of memory of each type that is commonly used is proportional to the size of its rectangle. The cost and speed of different type of memory are  compared in figure.