Sunteți pe pagina 1din 2

Practice Assignment –2010

Pointers, Arrays,File Handling


1. Give the output of the following program segment.
#include<iostream.h>
void POINTER(int *N, int j)
{ for(int i=1; i<j; i++)
*(N+i-1)=*(N+i)+1; }
void main( )
{ int a[ ]={ 12 , 19 , 20}, b[ ]={24, 13, 11}, c[ ]={ 5, 8,9};
POINTER (a,3);
POINTER (b,3);
POINTER(c,3);
for(int i=0;i<3;i++)
cout<<a[i]<<"@";
cout<<endl;
for(i=0;i<3;i++)
cout<<b[i]<<"*";
cout<<endl;
for(i=0;i<3;i++)
cout<<c[i]<<'#’;
cout<<endl; }

2. In the following program, find the correct possible output(s) from the options:

#include<stdlib.h>
#include<iostream.h>
void main()
{
randomize();
char Area[][10]={“NORTH”,”SOUTH”,”EAST”,”WEST”};
int ToGo;
for(int I=0;I<3;I++)
{
ToGo=random(3)+1;
cout<<Area[ToGo]<<”:”;
}
}

a) SOUTH:EAST:SOUTH:
b) NORTH:SOUTH:NORTH:
c) SOUTH:EAST:WEST:
d) WEST:EAST:EAST:

3. Write a function in c++ which accepts a 2D array of integers and its size as arguments
and displays the elements which lies on diagonals.
[Assuming the2D array to be a square matrix with odd dimensions , i.e 3x3, 5x5,7x7, etc]
Example if the array content is
543
678
129
Output through the function should be
Diagonal one : 5 7 9
Diagonal two : 3 7 1 .

4. Observe the program segment given below carefully and fill the blanks marked as
Statement 1 and Statement 2 using seekg() andtellg() functions for performing the
required task.

5. Write a function in C++ to count the number of alphabets present in a text file

6. An array Arr[50][10] is store in the memory along the row with each element
occupying 2 bytes. Find out the Base address of the location Arr[20][50], if the
location Arr[10][25] is stored at the address 10000.

7. Distinguish between * and & operators.

8. How can be arrays be allocated dynamic memory?Show using example.

S-ar putea să vă placă și