You are on page 1of 20

Chapter 4

Pointers, Structures & Unions


1. Simple Variables: (What is pointer? explain with examples)
int number=10;

variable memory address


number 10 4000

cout<<number ; prints 10
cout<<&number ; 4000

2. Reference Variables:
Ref. vars. are also called as alias variables which are used to give another name to
existing variable.
int n=5;
int &m=n;

here n & m both points to same location hence if n changed m also get changed or vice
versa.

3. Pointers:
Pointers are variables which points to address of a variable. For declaration * is used.

int *p , n = 10; Var Memory Address


p = &n; n 10 5000
p 5000 6000
p gives address of n i.e. 5000
*p gives value at address 5000 i.e. 10
&p gives its own address i.e. 6000

#include<iostream.h>
#include<conio.h>
void main()
{
int i=10, *p;
clrscr(); Output
p = &i;
cout<<”\nValue of i: “<<i; 10
cout<<”\nValue of i: “<<*p; 10
cout<<”\nValue of i: “<<*(&i); 10

cout<<”\nAddress of i: “<<&i; 5000


cout<<”\nAddress of i: “<<p; 5000

cout<<”\nValue of p: “<<p; 5000


cout<<”\nValue of p: “<<*(&p); 5000
cout<<”\nValue of p: “<<&p; 6000
}

CP Notes By Thombre D V Page 1 of 19


Chapter 4
Pointers, Structures & Unions
4. Pointers to pointers: (How double pointers are used?)
Its also called as double pointer.

Variable Memory Address Type of var


i 10 3000 simple int
p 3000 4000 single pointer
pp 4000 5000 double pointer

#include<iostream.h>
void main()
{
int i=5, *p, **p;
p=&i;
pp=&p;
Output
cout<<” Value of i “ << i; 10
cout<<”\n Value of i “ << *p; 10
cout<<”\n Value of i “ << *(&i); 10
cout<<”\n Value of i “ << **p; 10

cout<<”\n Address of i “ << &i; 3000


cout<<”\n Address of i “ << p; 3000

cout<<”\n Address of p “ << &p; 4000


cout<<”\n Address of p “ << pp; 4000
cout<<”\n Value of pp “ << pp; 4000
cout<<”\n Address of pp “ <<& pp; 5000
}
5. new Operator:(Explain new and delete operator)
float *p;
Here float pointer is declared & address of any variable can be assigned to it.
But if variables address is not assigned then we can not store any value at
pointer since pointer is not having address. Hence we need a operator to
allocate. This operator is new.

int i=5, *p; int *m;


p=&i; *p is nothing
*p=3 ; Not valid since no memory allocated
*p is 5
int *m;
m=new int; Allocates memory to store value.
*m=5; Valid

CP Notes By Thombre D V Page 2 of 19


Chapter 4
Pointers, Structures & Unions
6. delete Operator:
This operator is used to un-allocate memory assigned by new operator.
float *m=new float(3.55);
*m=5.55 ; Allowed
delete m;
*m=2.22; Not allowed since memory unallocated
7. Pointer to array: (Explain how pointer is used for arrays?)
// Program to display array by using pointers
#include<iostream.h>
void main()
{
int Num[5]={10,5,15,25,35};
int *ptr,*ptr1;
ptr=&Num[0]; // can be written as ptr=Num ;
ptr1=Num+5;
cout<<”Print the elements \n”;
while(ptr < ptr1)
{
cout<<*ptr <<”\n”;
ptr++;
}
}

// Program to pass array to function & print by pointer


#include<iostream.h>
void main()
{
void add2(int a[]);
int Num[5]={10,5,15,25,35};
int *start,*end;
start=Num;
end=Num+5;
add2(Num); //Only Name of array passed as argument
cout<<”Print the elements \n”;
for(;start < end;start++)
{
cout<<*start <<”\n”;
}
}
void add2(int a[])
{
for(int i=0;i<5;i++)
a[i]=a[i]+5;
}
7. Dynamic arrays:
float Num[20]; Static array
float *Num=new float[20]; Dynamic array

CP Notes By Thombre D V Page 3 of 19


Chapter 4
Pointers, Structures & Unions
8. Array of Pointers:
float *p[4];
p[0]=new float(5.555);
p[1]=new float(3.333);

9. Pointer to function: (Explain the use of pointer for accessing functions)


//function without arguments
#include<iostream.h>
void main()
{
double (*a) (); // Pointer to function
double function();
double result;
a=function; //assign function add to pointer a
result=(*a)(); //call function by pointer
cout<<”Result “<<result;
}

double function()
{
double a, b;

a=10.5;
b=20.5;
a=a + b;
return(a);
}

//function with arguments


#include<iostream.h>
void main()
{
double (*a) (double,int); // Pointer to function
double function(double a, int b);
double result;
a=function; //assign function add to pointer a
result=(*a)(10.55,50); //call function by pointer
cout<<”Result “<<result;
}

double function(double a, int b)


{
a=a + b;
return(a);
}

CP Notes By Thombre D V Page 4 of 19


Chapter 4
Pointers, Structures & Unions
//function returning a pointer
#include<iostream.h>
void main()
{
int *square(int *a); // Pointer returning function
int result;
cout<<”i= ”;
i>>i;
result=square(&i);
cout<<”square(i): “<<*result;
}
int *square(int *a)
{
*a=*a * *a;
return(a);
}
2 Structure: (Explain the structure )
Structures are used to store variety of data in a single variable. By default structure
variables are public.
struct book struct book
{ {
char BName[50]; char BName[50];
float Price; float Price;
int Pages; int Pages;
}; } b1, b2, b3 ;

struct book b1, b2, b3;


Ex.
#`include<iostrean.h>
void main()
{
struct book
{
char BName[50];
float Price;
int Pages;
} b1, b2, b3 ;
cout<<”Enter the Name, Price & Pages of 3 Books \n“;
cin>>b1.BName>>b1.Price>>b1.Pages;
cin>>b2.BName>>b2.Price>>b2.Pages;
cin>>b3.BName>>b3.Price>>b3.Pages;
cout<<”Entered Book details \n“;
cout<<b1.BName<<”\t”<<b1.Price<<”\t”<<b1.Pages<<endl;
cout<<b2.BName<<”\t”<<b2.Price<<”\t”<<b2.Pages<<endl;
cout<<b3.BName<<”\t”<<b3.Price<<”\t”<<b3.Pages<<endl;
}

CP Notes By Thombre D V Page 5 of 19


Chapter 4
Pointers, Structures & Unions

// Program for structure within structures


#`include<iostrean.h>
void main()
{
struct date
{ int day;
int month;
int year;
};
struct item
{
char *ItemName ;
int price;
struct date mnfDate;
}
}

struct item a;
a.ItemName=”Soap” ;
a.Price=10;
a.mnfDate.day=3;
a.mnfDate.month=10;
a.mnfDate.year=2007;
cout<<”\n Name :”<<a.ItemName;
cout<<”\n Price :”<<a.Price;
cout<<”\n Date :”<<a.mnfDate.day<<”/”;
cout<<a.mnfDate.month<<”/”;
cout<<a.mnfDate.year;
}
//Program on structure local to function
#include<iostream.h>
void main()
{ void function();
function();
getch();
}
void function()
{ struct date
{ int day;
int month;
int year;
};
struct date today={2,10,2007};
cout<<”Todays date is “<<today.day<<today.month<<today.year;
}

CP Notes By Thombre D V Page 6 of 19


Chapter 4
Pointers, Structures & Unions
// Structure Passed to a Function
#include<iostream.h>
struct Student
{ int RollNo;
int Marks1;
int Marks2;
}
void main()
{ void PrintStr(struct Student s1);
float FindAvg(struct Student s1);
struct Student s1={10,85,76};
PrintStr(s1);
cout<<”Average Marks are =“<<FindAvg(s1);
}
void PrintStr(struct Student s1)
{ cout<<”\n Student Record \n“;
cout<<”Roll No “<<s1.RollNo<<endl;
cout<<”Marks1 “<<s1.Marks1<<endl;
cout<<”Marks2 “<<s1.Marks2<<endl;
}
float FindAvg(struct Student s1)
{ float Avg;
Avg=s1.Marks1+s1.Marks2;
Avg=Avg/2;
return(Avg);
}
//Function Returning a Structure
#include<iostream.h>
struct Student
{ int RollNo;
int Marks1;
int Marks2;
}
void main()
{ struct Student function();
struct Student S;
float Result;
S=function();
cout<<”|n Student Record \n“;
cout<<”Roll No “<<S.RollNo<<endl;
cout<<”Marks1 “<<S.Marks1<<endl;
cout<<”Marks2 “<<S.Marks2<<endl;
}
struct Student function() //structure definition
{ struct Student s1={100,70,80};
return(s1);
}

CP Notes By Thombre D V Page 7 of 19


Chapter 4
Pointers, Structures & Unions
// Array of structures
#include<iostream.h>
struct Student
{
char SName[20];
char SAdd[30];
long int STel;
}
void main()
{
struct Student input();
struct Student S[5];
int i, j, n ;
cout<<”Enter No of Student “;
cin>>n;
for(i=0;i<n;i++)
S[i]=input();
cout<<”\n Display Information \n”;
for(i=0;i<n;i++)
{
cout<<”\n Name:”<<S[i].SName<<endl;
cout<<”\n Add ”<<S[i].SAdd<<endl;
cout<<”\n Tel :”<<S[i].STel<<endl;
}
} struct Student input()
{ struct Student S;
long int no;
int i;
cout<<”Enter Name Address & Tel No \n”;
cin>>S.SName>>S.SAdd>>S.Stel;
return(S);
}
//Program for Pointer to structure
#include<iostream.h>
void main()
{ struct sample
{ int x;
int y;
} a, *b;
a.x=10;
a.y=20;
b=&a;
cout<<”X=”<<(*b).x<<endl;
cout<<”Y=”<<(*b).y<<endl;
cout<<”X=”<<b->.x<<endl;
cout<<”Y=”<<b->y<<endl;
}

CP Notes By Thombre D V Page 8 of 19


Chapter 4
Pointers, Structures & Unions
//Program for Array of structure as a fucnction argument
/* Array of Students as a function argument */
#include <iostream.h>
#include <conio.h>
struct student
{ int roll_no ;
int physics_marks ;
int chemistry_marks ;
float average_marks ;
} ;
void main ()
{ void find_average ( struct student a[] ) ;
/* array of structure initialisation --
( average_marks are initially set to 0 ) */
struct student s[5] = { { 1, 50, 70, 0 },
{ 2, 67, 89, 0 },
{ 3, 78, 87, 0 },
{ 4, 56, 77, 0 },
{ 5, 49, 45, 0 } } ;
int i ;
clrscr ();
find_average ( s ) ;
cout<<"Student Information --\n\n" ;
for ( i = 0; i < 5; i++ )
{
cout<< "Student Roll No. : "<<s[i].roll_no<<endl ;
cout<< "Physics marks : "<<s[i].physics_marks<<endl;
cout<<"Chemistry marks : "<<s[i].chemistry_marks<<endl;
cout<<"Average marks : "<<s[i].average_marks<<endl;
}
getch ();
}
void find_average ( struct student a[] )
{ int i ;
for ( i = 0; i < 5; i++ )
{a[i].average_marks = a[i].physics_marks+a[i].chemistry_marks ;
a[i].average_marks /= 2 ;
}
}
//Program for Pointer to Structure
/*Program for Pointer to Structure */
#include <iostream.h>
#include <conio.h>
void main ()
{ struct samplr
{ int x ;
int y ;
} a, *b ;
a.x = 10 ;
a.y = 20 ;
b = &a;
cout<<"x : " <<(*b).x<<endl;
cout<<"y : "<<(*b).y<<endl ;
cout<<"x : " <<b->x<<endl;
cout<<"y : "<<b->y<<endl ;
getch ( ) ;
}

CP Notes By Thombre D V Page 9 of 19


Chapter 4
Pointers, Structures & Unions
//Program for Array of Pointer to Structure
/*Array of pointers to structure */
#include <iostream.h>
#include <conio.h>
struct sample
{
int a ;
char b ;
} ;
void main ()
{
/* Array of pointers to structure declaration */
struct sample *array[5] ;
/* structure declaration and initialisation */
struct sample s1 = { 1, 'A' } ;
struct sample s2 = { 2, 'B' } ;
struct sample s3 = { 3, 'C' } ;
struct sample s4 = { 4, 'D' } ;
struct sample s5 = { 5, 'E' } ;
int i ;
clrscr ();
array[0] = &s1; /* pointer assignment */
array[1] = &s2;
array[2] = &s3;
array[3] = &s4;
array[4] = &s5;
for ( i = 0; i < 5; i++ ) /* accessing through pointers */
{ cout<<"Contents of structure ... "<<i+1 ;
cout<<"a : "<<(*array[i]).a<<endl ;
cout<<"b : "<<(*array[i]).b<<endl ;
}
getch ();
}

3. Union:
Union & structure are both same in nature & in use. Memory requirement of union is less
as compared with structure. The memory used for struct is addition of all data type used
in structure where as memory of union is the highest memory data type in union. Since
all variables use same memory once we use next variable first is removed from memory
& hence if we print its value gives wrong result.
struct st union un
{ {
int j; int j;
float x; float x;
char p; char p;
}; };
Here memory requirement of structure is 2 + 4 + 1 =7 Bytes.
Where as memory requirement of union is 4 Bytes i.e. highest memory data type x.

CP Notes By Thombre D V Page 10 of 19


Chapter 4
Pointers, Structures & Unions
/* Program for Use of Union */
#include <iostream.h>
#include <conio.h>
void main ( )
{ union sample /* union declaration */
{ int a ;
char b ;
float c ;
} ;
union sample s ; /* union variable declaration */
clrscr ( ) ;
s.a = 10 ; /* stored as integer and retrieved as integer */
cout<<"a : "<<s.a ;

/* stored as character and retrieved as character */


s.b = 'x' ;
cout<<"b : "<<s.b<<endl ;
/* stored as float and retrieved as float */
s.c = 100.34 ;
cout<<"c : "<<s.c<<endl ;
/*stored as float and retrieved as integer-a wrong way*/
s.c = 1.567 ;
cout<<"a : "<<s.a <<endl;
getch ( ) ;
}

//Program for structure within Union


#include <iostream.h>
#include <conio.h>
void main ( )
{
struct date
{ int day ;
int month ;
int year ;
} ;
union sample
{ char *sample_date_1 ;
struct date sample_date_2 ; /* structure within union */
} ;
union sample s ; /* union variable declaration */
clrscr ( ) ;
/* stored as string and retrieved as string */
s.sample_date_1 = "2 Nov 1999" ;
cout<<"Date : "<<s.sample_date_1;

/* stored as structure and retrieved as structure */


s.sample_date_2.day = 2 ;
s.sample_date_2.month = 11 ;
s.sample_date_2.year = 1999 ;
cout<<"Date : "<<s.sample_date_2.day;
cout<<" / "<<s.sample_date_2.month ;
cout<<"/"<<s.sample_date_2.year ;
getch () ;
}

CP Notes By Thombre D V Page 11 of 19


Chapter 4
Pointers, Structures & Unions
3. Linked List
It’s a data structure used to store similar data in a memory. Elements
of LL are not stored in continuous memory locations. They are
scattered but linked to each other.

Info Next Info Next Info Next


List
4 4 4 Null

node node node

Linked list structure

A new node can be added to existing list by creating a link between


the added node & nodes after or before it.
A node can be deleted from a list by creating a link between its
previous & next node.

/*Program for dynamic implementation of linked list*/


#include<iostream.h>
#include<conio.h>

struct node
{
int info;
struct node *next;
};
struct node *list=0;
struct node * getnode(void)
{
/*function to allocate memory for new node*/
return((struct node*)new(struct node));
}/*end getnode*/

void freenode(struct node *p)


{
/*free dynamically allocated memory*/
delete(p);
}/*end freenode*/
void display()
{
/*display all nodes*/
int i;
struct node *t;
t=list;
if(t==NULL)
cout<<"\nThe linked list is empty";
else
{ cout<<"\n";
while(t!=NULL)
{

CP Notes By Thombre D V Page 12 of 19


Chapter 4
Pointers, Structures & Unions
cout<<"-->|"<<t->info<<"|";
t=t->next;
}
}
}/*end display*/
void insertbeg(int x)
{
/*insert new element at the beginning of linked list*/
struct node *q;
q=getnode();
q->info=x;
q->next=list;
list=q;
display();
}/*end insertbeg*/

void insertend(int x)
{
/*insert new element at the end of linked list*/
struct node *q,*temp;
q=getnode();
q->info=x;
q->next=NULL;
temp=list;
if(temp==NULL)
list=q;
else
{
while(temp->next!=NULL)
temp=temp->next;
temp->next=q;
}
display();
}/*void insertend*/
void insafter(int p,int x)
{
/*insert new element after a specific node*/
struct node *q,*t;
int i;
if(list==NULL)
cout<<"\nInvalid insertion";
else
{
t=list;
for(i=0;i<p-1;i++)
t=t->next;
q=getnode();
q->info=x;
q->next=t->next;
t->next=q;
display();
}
}/*end insafter*/
void delafter(int p)
{
/*delete new element after a specific node*/
int x,i;
struct node *t,*q;

CP Notes By Thombre D V Page 13 of 19


Chapter 4
Pointers, Structures & Unions
t=list;
for(i=0;i<p-1;i++)
t=t->next;
if((list==NULL)||(t->next==NULL))
cout<<"\nInvalid deletion(list is empty/end of list)";
else
{
q=t->next;
x=q->info;
t->next=q->next;
freenode(q);
cout<<"\nThe deleted element is "<<x;
}
display();
}/*end delafter*/
void deletebeg(void)
{
/*delete a node from the beginning of the linked list*/
int x;
struct node *q;
q=list;
if(list==NULL)
cout<<"\nThe linked list is empty";
else
{
x=q->info;
list=q->next;
cout<<"\nThe deleted element is "<<x;
freenode(q);
display();
}
}/*end deletebeg*/
void deleteend(void)
{
/*delete a node from the end of the linked list*/
struct node *q,*temp;
int x;
q=list;
if(q==NULL)
cout<<"\nThe linked list is empty";
else
{
if(q->next==NULL)
{
x=q->info;
list=NULL;
}
else
{
while(q->next!=NULL)
{
temp=q;
q=q->next;
}
x=q->info;
temp->next=NULL;
}
cout<<"\nThe deleted element is "<<x;

CP Notes By Thombre D V Page 14 of 19


Chapter 4
Pointers, Structures & Unions
freenode(q);
}
display();
}/*end deleteend*/
void insloc(int p,int x)
{
/*insert new node at a specific location*/
int t,i;
struct node *q,*temp;
temp=list;
for(i=0;i<(p-2);i++)
{
temp=temp->next;
if(temp==NULL)
{
cout<<"\nThere are less than "<<p<<"elements in list "<<p;
break;
}
}
if(temp!=NULL)
{
q=getnode();
q->info=x;
q->next=temp->next;
temp->next=q;
}
display();
}/*end insloc*/
void delloc(int p)
{
/*delete a node from a specific location*/
int i;
struct node *temp,*t;
temp=list;
if(p==1)
list=list->next;
for(i=0;i<p-1;i++)
{
if(temp->next==NULL)
{
cout<<"\nThere are less than "<<p<<"elements in list "<<p;
break;
}
t=temp;
temp=temp->next;
}
if(temp->next!=NULL)
{
cout<<"\nThe deleted element is "<<temp->info;
t->next=temp->next;
freenode(temp);
}
display();
}/*end delloc*/

CP Notes By Thombre D V Page 15 of 19


Chapter 4
Pointers, Structures & Unions
void search(int x)
{
/*search a node in linked list*/
struct node *t;
int i;
for(t=list,i=0;t!=NULL;t=t->next,i++)
{
if(t->info==x)
{
cout<<"\nPosition of element "<<x<<"is "<<i+1<<endl;
break;
}
}
if(t==NULL)
cout<<"\nElement not found";
display();
}/*end search*/
void main()
{
struct node * getnode(void);
int ch,p,info,x;
char ans='y';

clrscr();
cout<<"\n\tDynamic Linked List";
cout<<"\n1.Insert after a node";
cout<<"\n2.Delete after a node";
cout<<"\n3.Insert at begining ";
cout<<"\n4.Delete at begining ";
cout<<"\n5.Insert at end ";
cout<<"\n6.Delete at end ";
cout<<"\n7.Insert at location";
cout<<"\n8.Delete at location";
cout<<"\n9.Search an element";
back:cout<<"\nEnter ur choice : ";
cin>>ch;
switch(ch)
{
case 1: cout<<"\nEnter the node no : ";
cin>>p;
cout<<"\nEnter the info : ";
cin>>x;
insafter(p,x);
break;
case 2: cout<<"\nEnter the node no : ";
cin>>p;
delafter(p);
break;
case 3: cout<<"\nEnter the info : ";
cin>>x;
insertbeg(x);
break;
case 4: deletebeg();
break;
case 5: cout<<"\nEnter the info : ";
cin>>x;
insertend(x);
break;

CP Notes By Thombre D V Page 16 of 19


Chapter 4
Pointers, Structures & Unions
case 6: deleteend();
break;
case 7: cout<<"\nEnter the node no : ";
cin>>p;
cout<<"\nEnter the info : ";
cin>>x;
insloc(p,x);
break;
case 8: cout<<"\nEnter the node no : ";
cin>>p;
delloc(p);
break;
case 9 :cout<<"\nEnter the element : ";
cin>>x;
search(x);
break;
case 10: display();
break;
default:cout<<"\nWrong choice ";
}
cout<<"\nDo u want to continue(y/n)?";
cin>>ans;
if(ans=='y')
goto back;
}/*end main*/

//Program on structures

#include<iostream.h>
#include<conio.h>
#include<string.h>
struct student
{
char name[20],DOB[8];
int Marks,SeatNo;
} s[5];
main()
{
int i,j,temp;
char temp1[20];
for(i=0;i<5;i++)
{
cout<<"\n Enter the name of student : " <<i;

cin>>s[i].name;
cout<<"\n Enter the SeatNo of student : "<<i;
cin>>s[i].SeatNo;
cout<<"\n Enter the DOB of student : "<<i;
cin>>s[i].DOB;
cout<<"\n Enter the Marks of student : "<<i;
cin>>s[i].Marks;
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(s[i].SeatNo>s[j].SeatNo)

CP Notes By Thombre D V Page 17 of 19


Chapter 4
Pointers, Structures & Unions
{ temp=s[j].SeatNo;
s[j].SeatNo=s[i].SeatNo;
s[i].SeatNo=temp;

temp=s[j].Marks;
s[j]. Marks =s[i]. Marks;
s[i]. Marks =temp;

strcpy(temp1,s[j].DOB);
strcpy(s[j].DOB,s[i].DOB);
strcpy(s[i].DOB,temp1);

strcpy(temp1,s[j].name);
strcpy(s[j].name,s[i].name);
strcpy(s[i].name,temp1);
}
}
for(i=0;i<5;i++)
{ cout<<"\n Name : "<< s[i].name<<"\t SeatNo :
"<<s[i].SeatNo<<"\tDOB : "
<<s[i].DOB <<"\t Marks : "<<s[i].Marks;
}
}
return(0);
}
//Program on structures
#include <iostream.h>
#include <conio.h>
struct COMPUTER
{
char CPUtype[15],CDROM_type[10],mouse_type[15];
char key_board_type[15],SVGA_monitor_make[15];
int SDRAM_size,HDD_size;
float clock_speed,CDROM_speed;
} comp[50];
void main()
{
int i;
clrscr();
for(i=0;i<50;i++)
{
cout<<"\nEnter CPU tpye, CDROM_type, mouse_type";
cin>>comp[i].CPUtype>>comp[i].CDROM_type>>comp[i].mouse_type;
cout<<"Enter key_board_type, SVGA_monitor_make";
cin>>comp[i].key_board_type>>comp[i].SVGA_monitor_make;
cout<<"Enter SDRAM_size, HDD_size";
cin>>comp[i].SDRAM_size>>comp[i].HDD_size;
cout<<"Enter clock_speed, CDROM_speed";
cin>>comp[i].clock_speed>>comp[i].CDROM_speed;
}
for(i=0;i<50;i++)
{ if(comp[i].HDD_size> 8)
{
cout<<"CPU type is "<<comp[i].CPUtype;
}
}
}

CP Notes By Thombre D V Page 18 of 19


Chapter 4
Pointers, Structures & Unions
// Searching for an address
#include <iostream.h>
int* location(int[],int,int);
void main()
{ int a[8] = {22, 33, 44, 55, 66, 77, 88, 99}, * p=0, n;
do
{ cin >> n;
if (p == location(a, 8, n)) cout << p << ", " << *p << endl;
else cout << n << " was not found.\n";
} while (n > 0);
}
int* location(int a[], int n, int target)
{ for (int i = 0; i < n; i++)
if (a[i] == target) return &a[i];
return NULL;
}

CP Notes By Thombre D V Page 19 of 19


Filename: chap 4.doc
Directory: E:\dvt\Subjects\F.E\Notes CP
Template: C:\Documents and Settings\Thombre\Application
Data\Microsoft\Templates\Normal.dotm
Title: 1
Subject:
Author: DVT
Keywords:
Comments:
Creation Date: 10/2/2007 10:06:00 AM
Change Number: 21
Last Saved On: 3/25/2010 10:52:00 AM
Last Saved By: Thombre D v
Total Editing Time: 551 Minutes
Last Printed On: 3/25/2010 10:52:00 AM
As of Last Complete Printing
Number of Pages: 19
Number of Words: 3,024 (approx.)
Number of Characters: 17,238 (approx.)

You might also like