## Program to find sum of diagonals in a 2D matrix using pointers

```#include<stdio.h>
main()
{
int i,j,a,b,sum=0,k=0,m=0,n;
int *p,*q,*r;
int arr[50][50];
printf("Enter size of the row or column.\n");
scanf("%d",&a);
printf("Enter the elements of the array:\n");
for(i=0 ;i<a ;i++)
{
for(j=0;j<a;j++)
{

scanf("%d",&arr[i][j]);
}
}
for(i=0;i<a;i++)
{
p=&arr[i];
sum=sum + *(p+m);
m=m+1;
}

printf("Sum of diagonals is %d",sum);

}```

OUTPUT:

```Enter size of the row or column.
2
Enter the elements of the array:
1
2
3
4
Sum of diagonals is 5```

OUTPUT:

## Copy a character array in another character array using pointers and without using inbuilt function

```#include<stdio.h>
#include<string.h>
main()
{
char str1[100],str2[100],*a,*b;
int i,k,l,m;
printf("Enter string 1\n");
gets(str1);
printf("Enter string 2\n");
gets(str2);
m=strlen(str1);
k=strlen(str1);
l=strlen(str2);
a=&str1;
b=&str2;
for(i=0;i<l;i++)
{
*(a+i)=*(b+i);
}
printf("Copied String - ");
for(i=0;i<l;i++)
{
printf("%c",*(a+i));
}

}```

OUTPUT: