C Programming - PointersOrganized By: Vinay Arora               Assistant Professor, CSED               Thapar University,...
Program - 1 #include<stdio.h>                                   void swapr(int x, int y) #include<conio.h>                ...
Program – 1 (output)                Vinay Arora                   CSED
Program - 2 #include<stdio.h>                                   void swapr(int *x, int *y) #include<conio.h>              ...
Program – 2 (output)                Vinay Arora                   CSED
Program - 3  #include<stdio.h>                                    void areaperi(int r, float *a, float *p)  #include<conio...
Program – 3 (output)                Vinay Arora                   CSED
Passing Array Value (CBVal)                Vinay Arora                   CSED
Passing Array Reference (CBRef)                Vinay Arora                   CSED
Vinay Arora   CSED
Program - 4        #include<stdio.h>        #include<conio.h>        void main()         {          int i, *x;          cl...
Program – 4 (output)                Vinay Arora                   CSED
Program - 5        #include<stdio.h>        #include<conio.h>        void main()         {          int a=10, b=20, *p, *j...
Program – 5 (output)                Vinay Arora                   CSED
Program - 6  #include<stdio.h>  #include<conio.h>                             printf("nj - i = %d",j-i);                  ...
Program – 6 (output)                Vinay Arora                   CSED
Program - 7  #include<stdio.h>                                   for(i=0;i<=5;i++)  #include<conio.h>                     ...
Program – 7 (output)                Vinay Arora                   CSED
Program – 8 (Diff. notations for accessing Array)    #include<stdio.h>                                getch();    #include...
Program – 8 (output)                Vinay Arora                   CSED
Program - 9         #include<stdio.h>         #include<conio.h>         void main()          {           int s[3][2]={    ...
Program – 9 (output)                Vinay Arora                   CSED
Program – 10 (Conti…)  #include<stdio.h>                           printf("Notation Used is s[i][j])n");  #include<conio.h...
Program – 10 (Conti…)  #include<stdio.h>                 printf("nAccessing 2-D Arrayn");  #include<conio.h>              ...
Program – 10 (Conti…)  #include<stdio.h>                printf("nAccessing 2-D Arrayn");  #include<conio.h>               ...
Program – 10 (output)                Vinay Arora                   CSED
Program – 11 (Array of Pointer) #include<stdio.h>             printf("Address of variable a,b,cn"); #include<conio.h>     ...
Program – 11 (output)                Vinay Arora                   CSED
Thnx…  Vinay Arora     CSED
Upcoming SlideShare
Loading in...5
×

C Prog - Pointers

1,027

Published on

Published in: Education, Business, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,027
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
87
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

C Prog - Pointers

  1. 1. C Programming - PointersOrganized By: Vinay Arora Assistant Professor, CSED Thapar University, Patiala
  2. 2. Program - 1 #include<stdio.h> void swapr(int x, int y) #include<conio.h> { void swapr(int,int); int t; int main() t=x; { x=y; int a=10,b=20; y=t; clrscr(); } printf("Value of variable a=%d and b=%d",a,b); swapr(a,b); printf("nValue of variable a=%d and b=%d",a,b); getch(); } Vinay Arora CSED
  3. 3. Program – 1 (output) Vinay Arora CSED
  4. 4. Program - 2 #include<stdio.h> void swapr(int *x, int *y) #include<conio.h> { void swapr(int *, int *); int t; int main() t=*x; { *x=*y; int a=10,b=20; *y=t; clrscr(); } printf("Value of variable a=%d and b=%d",a,b); swapr(&a,&b); printf("nValue of variable a=%d and b=%d",a,b); getch(); } Vinay Arora CSED
  5. 5. Program – 2 (output) Vinay Arora CSED
  6. 6. Program - 3 #include<stdio.h> void areaperi(int r, float *a, float *p) #include<conio.h> { void areaperi(int,float *,float *); *a=3.14*r*r; int main() *p=2*3.14*r; { int radius; } float area, perimeter; clrscr(); printf("Enter radius of circle"); scanf("%d",&radius); areaperi(radius,&area,&perimeter); printf("Area=%fn",area); printf("Perimeter=%fn",perimeter); return 0; } Vinay Arora CSED
  7. 7. Program – 3 (output) Vinay Arora CSED
  8. 8. Passing Array Value (CBVal) Vinay Arora CSED
  9. 9. Passing Array Reference (CBRef) Vinay Arora CSED
  10. 10. Vinay Arora CSED
  11. 11. Program - 4 #include<stdio.h> #include<conio.h> void main() { int i, *x; clrscr(); printf("Enter any Integer Valuet"); scanf("%d",&i); x=&i; printf("nx=Address value of in"); printf("nValue of x = %u",x); x++; printf("nAfter Increment in Pointern"); printf("Value of x = %u",x); getch(); } Vinay Arora CSED
  12. 12. Program – 4 (output) Vinay Arora CSED
  13. 13. Program - 5 #include<stdio.h> #include<conio.h> void main() { int a=10, b=20, *p, *j; clrscr(); p=&a; j=&b; printf("nAddition *p + b = %d", *p + b); printf("nAddition *p + *j = %d", *p + *j); printf("nAddition *(p) + *(j) = %d", *(p) + *(j)); printf("nAddition *(&a) + *(&b) = %d", *(&a) + *(&b)); getch(); } Vinay Arora CSED
  14. 14. Program – 5 (output) Vinay Arora CSED
  15. 15. Program - 6 #include<stdio.h> #include<conio.h> printf("nj - i = %d",j-i); printf("n*j - *i =%d",*j - *i); void main() { getch(); int arr[]={10,20,30,45,67,56,74}; } int *i,*j; int x; clrscr(); printf("Array Elements are"); for(x=0;x<=6;x++) { printf("n Value at arr[%d] is %d",x,arr[x]); } i=&arr[1]; j=&arr[5]; Vinay Arora CSED
  16. 16. Program – 6 (output) Vinay Arora CSED
  17. 17. Program - 7 #include<stdio.h> for(i=0;i<=5;i++) #include<conio.h> { printf("nAddress = %u",j); void main() printf("nElement = %d",*j); { j++; int num[]={24,34,12,44,56,17}; } int i,*j; getch(); clrscr(); } printf("Array Elements are"); for(i=0;i<=5;i++) { printf("n Value at arr[%d] is %d",i,num[i]); } j=&num[0]; Vinay Arora CSED
  18. 18. Program – 7 (output) Vinay Arora CSED
  19. 19. Program – 8 (Diff. notations for accessing Array) #include<stdio.h> getch(); #include<conio.h> } void main() { int num[]={24,34,12}; int i; clrscr(); printf("Array Elements are"); for(i=0;i<=2;i++) { printf("n Value at arr[%d] is %d",i,num[i]); printf("n Value at arr[%d] is %d",i,i[num]); printf("n Value at arr[%d] is %d",i,*(num+i)); printf("n Value at arr[%d] is %d",i,*(i+num)); printf("n"); } Vinay Arora CSED
  20. 20. Program – 8 (output) Vinay Arora CSED
  21. 21. Program - 9 #include<stdio.h> #include<conio.h> void main() { int s[3][2]={ {10,15}, {20,25}, {30,35} }; int i; clrscr(); for(i=0;i<=2;i++) printf("Address of %dth 1-D array = %un",i,s[i]); getch(); } Vinay Arora CSED
  22. 22. Program – 9 (output) Vinay Arora CSED
  23. 23. Program – 10 (Conti…) #include<stdio.h> printf("Notation Used is s[i][j])n"); #include<conio.h> for(i=0;i<=2;i++) void main() { { for(j=0;j<=1;j++) int s[3][2]={ { {10,15}, printf("t%d",s[i][j]); {20,25}, } {30,35} printf("n"); }; } int i,j; clrscr(); getch(); printf("Array Elements aren"); } Vinay Arora CSED
  24. 24. Program – 10 (Conti…) #include<stdio.h> printf("nAccessing 2-D Arrayn"); #include<conio.h> printf("Notation Used is *(s[i]+j)n"); void main() for(i=0;i<=2;i++) { { int s[3][2]={ for(j=0;j<=1;j++) {10,15}, { {20,25}, printf("t%d",*(s[i]+j)); {30,35} } }; printf("n"); int i,j; } clrscr(); getch(); } Vinay Arora CSED
  25. 25. Program – 10 (Conti…) #include<stdio.h> printf("nAccessing 2-D Arrayn"); #include<conio.h> printf("Notation Used is void main() *(*(s+i)+j)n"); { for(i=0;i<=2;i++) int s[3][2]={ { {10,15}, for(j=0;j<=1;j++) {20,25}, { {30,35} printf("t%d",*(*(s+i)+j)); }; } int i,j; printf("n"); clrscr(); } getch(); } Vinay Arora CSED
  26. 26. Program – 10 (output) Vinay Arora CSED
  27. 27. Program – 11 (Array of Pointer) #include<stdio.h> printf("Address of variable a,b,cn"); #include<conio.h> printf("%un",a); printf("%un",b); void main() printf("%un",c); { int *arr[3]; printf("Value Present in Arrayn"); int i=10, j=20, k=30, m; for(m=0;m<=2;m++) int *a,*b,*c; { printf("n%u",arr[m]); clrscr(); } printf("n"); printf("n"); arr[0] = &i; for(m=0;m<=2;m++) arr[1] = &j; for(m=0;m<=2;m++) { { arr[2] = &k; printf("n%d",*(arr[m])); printf("n%u",&arr[m]); } } a=&i; getch(); b=&j; } c=&k; Vinay Arora CSED
  28. 28. Program – 11 (output) Vinay Arora CSED
  29. 29. Thnx… Vinay Arora CSED
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×