DMA

/*A program to read & display elements using DDA*/ #include<stdio.h> #include<conio.h> void main() { int a[5][5],m,n,i,j; clrscr(); printf("Enter no.of rows and cols: "); scanf("%d %d",&m,&n); printf("Enter the matrix elements "); for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); printf("The array elements are \n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) printf("%d ",a[i][j]); printf("\n"); } getch(); } Output: Enter no.of rows and cols: 2 2 Enter the matrix elements 1 2 3 4 The array elements are 12 34 /*A program to read & display elements using DDA with DMA*/ /*Array of Pointer*/ #include<stdio.h> #include<conio.h> void main() { int *a[10],m,n,i,j; clrscr(); printf("Enter no.of rows and cols: "); scanf("%d %d",&m,&n); for(i=0;i<m;i++) a[i]=(int *)malloc(n*sizeof(int)); printf("Enter the matrix elements "); for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); //scanf("%d",*(a+i)+j); printf("The array elements are \n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) printf("%d ",a[i][j]); //printf("%d ",*(*(a+i)+j)); printf("\n"); } getch(); } Output: Enter no.of rows and cols: 2 2 Enter the matrix elements 1 2 3 4 The array elements are 12 34 /*A program to read & display elements using DDA with DMA*/ #include<stdio.h> #include<conio.h> void main() { int *a,m,n,i,j; clrscr(); printf("Enter no.of rows and cols: "); scanf("%d %d",&m,&n); a=(int *)malloc(m*n*sizeof(int)); printf("Enter the matrix elements "); for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",a+i*n+j); printf("The array elements are \n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) printf("%d ",*(a+i*n+j)); printf("\n"); } getch(); } Output: Enter no.of rows and cols: 2 2 Enter the matrix elements 1 2 3 4 The array elements are 12 34

/*A program to read & display elements using DDA with DMA*/ #include<stdio.h> #include<conio.h> void main() { int **a,m,n,i,j; clrscr(); printf("Enter no.of rows and cols: "); scanf("%d %d",&m,&n); a=(int **)malloc(m*sizeof(int)); for(i=0;i<m;i++) a[i]=(int *)malloc(n*sizeof(int)); printf("Enter the matrix elements "); for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); //scanf("%d",*(a+i)+j); printf("The array elements are \n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) printf("%d ",a[i][j]); //printf("%d ",*(*(a+i)+j)); printf("\n"); } getch(); } Output: Enter no.of rows and cols: 2 2 Enter the matrix elements 1 2 3 4 The array elements are

1

&m.j<2.h> void main() { int a[5][5]={{10. printf("\nEnter any two numbers: "). int i.i<3.int *y) { *x=*x+*y. int i.of rows and cols: "). //scanf("%d".b=20.h> void main() { int (*a)[10].j.h> #include<conio.60}}.bptr).a.*q=&b. printf("\nAfter swap a = %d\tb = %d". *x=*x-*y. *y=*x-*y. printf("\n").a[i][j]). clrscr(). swap(aptr.h> #include<conio.40}.h> #include<conio.h> void main() { char *names[10]. for(i=0.{50. printf("\nBefore swap a = %d\tb = %d".a[i]).40}}. } void swap(int *x. clrscr(). } Output: Enter no.&a. void main() { int a.i++) printf("a[%d] array address = %u\n".i++) { for(j=0. int i. bptr=&b. for(i=0.h> #include<alloc.h> #include<conio.n.j++) scanf("%d".*aptr. void *v1=p.int *).h> void swap(int *. aptr=&a. } Output: a[0] array address = 65514 a[1] array address = 65518 a[2] array address = 65522 /*W. a=(int *)malloc(m*sizeof(int)). clrscr().h> void main() { int a=10.*(a+i)+j).i<m.i<m.a.h> void main() { int a[3][2]={{10.j. //printf("%d ". printf("The matrix elements are\n").{30.*(*(a+i)+j)).j<n.*v2=q.h> #include<conio.b). printf("Enter no. int *p=&a.j++) printf("%d ". scanf("%d%d". getch(). #include<stdio. printf("Enter the matrix elements ").A.of rows and cols: 2 2 Enter the matrix elements 1 2 3 4 The array elements are 12 34 #include<stdio. } getch().{30. clrscr(). clrscr(). getch().P to interchange two numbers in calling function from called function*/ #include<stdio.b). } Output: Enter any two numbers: 20 30 Before swap a = 20 After swap a = 30 b = 30 b = 20 #include<stdio. printf("The array elements are \n"). for(i=0.*(*(a+i)+j)).n.b. } Output: The matrix elements are 10 20 30 40 /*A Program on void pointer*/ #include<stdio.m. for(i=0.12 34 /*A program to read & display elements using DDA with DMA*/ /*Pointer to Array*/ #include<stdio.i.i++) for(j=0.&n).20}.j++) printf("%d ".&a[i][j]).i<2.20}.&b).i++) { for(j=0. 2 .*bptr.j<n. scanf("%d %d".h> #include<conio. } getch().i. printf("\n").

i++) names[i]=(char *)malloc(n*sizeof(char)). of names: ").h> void main() { int *p=NULL.i<n. for(i=0. clrscr(). } else { printf("Memory is allocated").i<n.h> #include<conio.&n). } Output: Memory is not allocated 3 . for(i=0.clrscr(). printf("%d ". } free(a). printf("%d". scanf("%s".h> #include<conio. } printf("The names are\n"). scanf("%d". } free(a). of names: 3 Enter names Enter 1 name: aaa Enter 2 name: sss Enter 3 name: dff The names are aaa sss dff /*An example program on Free*/ #include<stdio. } Output: 10 20 printf("Enter no. getch().h> void main() { float *a. } Output: Enter no. a=(float *)malloc(0*sizeof(float)).h> #include<stdlib. } Output: Memory is allocated /*Aprogram od NULL pointer*/ #include<stdio.i++) puts(names[i]).p). clrscr().i<n. getch(). a=(float *)malloc(5*sizeof(float)). getch(). getch().names[i]).*((int *)v1)). } else { printf("Memory is allocated").h> void main() { float *a. for(i=0. printf("%d". if(a==NULL) { printf("Memory is not allocated"). printf("Enter names\n"). getch(). } Output: 0 /*An example program on Free*/ #include<stdio.i++) { printf("Enter %d name: ". clrscr(). if(a==NULL) { printf("Memory is not allocated").h> #include<conio.*((int *)v2)).h> #include<stdlib.i+1).

Sign up to vote on this title
UsefulNot useful