Tuesday, 24 February 2015

Pointers in C++

#include<iostream.h>
#include<conio.h>
void main()
{
int i,*iptr;
iptr=&i;
i=20;
clrscr();
cout<<”I value is:”<<i<<endl;
*iptr=*iptr+30;
cout<<”I value is:”<<i<<endl;
getch();
}

=======================

#include<iostream.h>
#include<conio.h>
void main()
{
int arr[5]={10,20,30,40,50};
int *ptr,i;
clrscr();
ptr=arr;
for(i=0;i<5;i++)
{
cout<<*(ptr+i)<<”\t”;
*(ptr+i)=*(ptr+i)+5;
}
cout<<endl;
for(i=0;i<5;i++)
cout<<arr[i]<<endl;
getch();
}

===============================

#include<iostream.h>
#include<conio.h>
void main()
{
char name[10];
char *cptr;
clrscr();
cout<<”Enter the name in lower case:”;
cin>>name;
for(;*cptr!=’\0’;*cptr++)
{
if(*cptr>=’a’ && *cptr<=’z’)
*cptr=*cptr-32;
}
cout<<”Upper case is:”<<name<<endl;
getch();

}

No comments:

Post a Comment