Program to concatinate two strings using pointers

#include<stdio.h>
main()
{
int i,j=0,k,l,m,n,o;
char *p,*q,str1[50],str2[50];

printf("Enter string 1\n");

gets(str1);
printf("Enter string 2\n");
gets(str2);
p=str1;
q=str2;
k=strlen(str1);
l=strlen(str2);
m=k+l;
n=k;
for(i=0;i<=l;i++)
{
*(p+n)=*(q+i);
n++;

}
printf("Concatination of 2 strings is ");
for(i=0;i<=k+l-1;i++)
{
printf("%c",*p);
p++;
}
}

Continue reading “Program to concatinate two strings using pointers”

Program to do increment of 2 on all elements of an array using pointers.

#include<stdio.h>
main()
{

int i[3][3]= {
{1,2,3},
{3,4,5},
{5,6,7}
};

int *p,*q,*r,k;
printf("Adding 2 to all elements of the array.\nArray Becomes:\n");
p=&i;
for(k=0;k<9;k++)
{
printf("%d\n",*(p+k)+2);
}

}

Continue reading “Program to do increment of 2 on all elements of an array using pointers.”