0% found this document useful (0 votes)
71 views

Pointers

The document discusses several C++ programs involving pointers and arrays. It provides the code for 6 programs (labeled a-f) and asks what the output would be for each. The programs demonstrate various pointer operations like dereferencing, incrementing, and passing arrays to functions by reference. They manipulate array elements using pointers and pointer arithmetic.

Uploaded by

Niti Arora
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Pointers

The document discusses several C++ programs involving pointers and arrays. It provides the code for 6 programs (labeled a-f) and asks what the output would be for each. The programs demonstrate various pointer operations like dereferencing, incrementing, and passing arrays to functions by reference. They manipulate array elements using pointers and pointer arithmetic.

Uploaded by

Niti Arora
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Computer Science (083)

Assignment : Pointers

Assignment : Pointers and Arrays


What will be the output of following programs :
a.
void main( )
{
int b[] = {10,20,30,40,50};
int i ;
for (i=0; i<=4; i++ )
cout << * (b+i);
}
b.

void main( )

{
int b[] = {10,20,30,40,50};
int i ;
for (i=0; i<=4; i++ )
cout << * b +i ;
}
c.

void main( )

{
int b[] = {10,20,30,40,50};
int i , *k;
k = b;
for (i=0; i<=4; i++ )
cout << * k ;
}
d.

void change( int * b, int n);

void main( )
{
int a[] = {2,4,6,8,10};
int i ;
change (a,5);
for (i=0; i<=4; i++ )
cout << a[i]<<#;
}
void change( int * b, int n)
{
int i;
for (i=0; i<=4; i++ )
*( b+i) = * (b+i)+5;
}

By Niti Arora

// Prototype declaration

Computer Science (083)


Assignment : Pointers
e.
void change( int * b, int n);
void main( )
{
int a[] = {2,4,6,8,10};
int i ;
change (a,5);
for (i=0; i<=4; i++ )
cout << a[i]<<#;
}
void change( int * b, int n)
{
int i;
for (i=1; i<=4; i++ )
{
if ( i%2==0)
*( b+i) = * (b+i)+5;
else
*(b+i) = * (b+i-1);
}
f.
void main( )
{
int a[5] = {5,1,15,20,25};
int i,j, k=1,m;
i = ++ a[k];
j = a[k] ++;
m = a[i++];
cout <<i<<@<<j<<@<<m;
}

By Niti Arora

// Prototype declaration

You might also like