You are on page 1of 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