// API callback
relpostimgcuplik({"version":"1.0","encoding":"UTF-8","feed":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns$blogger":"http://schemas.google.com/blogger/2008","xmlns$georss":"http://www.georss.org/georss","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$thr":"http://purl.org/syndication/thread/1.0","id":{"$t":"tag:blogger.com,1999:blog-8285804830535272268"},"updated":{"$t":"2023-07-30T02:11:08.392-07:00"},"category":[{"term":"C Programs"},{"term":"Learn C"},{"term":"Common Programming Error"},{"term":"searching and sorting"},{"term":"control sturctures"},{"term":"Fundamental"},{"term":"List of C Programs"},{"term":"string"},{"term":"Array"},{"term":"Pattern"},{"term":"Contents"},{"term":"Pointers"},{"term":"functions"},{"term":"Dynamic memory allcation"},{"term":"recursion"},{"term":"C Turbo Compiler"},{"term":"File Handling"},{"term":"Structures"}],"title":{"type":"text","$t":"C Programming Tutorial"},"subtitle":{"type":"html","$t":"It is a blog about c programming. Here we provide c programs and tutorials to enhance your skills."},"link":[{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"https:\/\/www.comp-psyche.com\/feeds\/posts\/default"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/8285804830535272268\/posts\/default\/-\/Pointers?alt=json-in-script\u0026max-results=50"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.comp-psyche.com\/search\/label\/Pointers"},{"rel":"hub","href":"http://pubsubhubbub.appspot.com/"}],"author":[{"name":{"$t":"Mantu Kumar"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"generator":{"version":"7.00","uri":"http://www.blogger.com","$t":"Blogger"},"openSearch$totalResults":{"$t":"3"},"openSearch$startIndex":{"$t":"1"},"openSearch$itemsPerPage":{"$t":"50"},"entry":[{"id":{"$t":"tag:blogger.com,1999:blog-8285804830535272268.post-6794134224349899676"},"published":{"$t":"2014-01-29T06:56:00.000-08:00"},"updated":{"$t":"2014-04-16T01:02:49.375-07:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"C Programs"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Pointers"}],"title":{"type":"text","$t":"C PROGRAMS : POINTERS"},"content":{"type":"html","$t":"\u003Cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003E\u003Ctitle\u003EC PROGRAMS : POINTERS\u003C\/title\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers1.html#p6\" name=\"p6\"\u003E6. Program to find maximum element of an array of elements using pointer\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\nint main()\n{\n \/\/ Declaring array variable \"a\" of size 10, i=to iterate loop, max=maximum element\n int a[10], i, max;\n \n \/\/ Declaring pointer variable pointing to the the base address i.e ( a[0] )of array 'a'  \n int *ptr=a; \/\/ It is equivalent to : int *ptr; ptr=\u0026amp;a;\n \n \/\/ Inputing array elements\n printf(\"Enter 10 elements in an array : \");\n for(i=0;i\u0026lt;10;i++)\n {\n  scanf(\"%d\",\u0026amp;a[i]);\n }\n \n \/\/ Assigning first element to max, ptr points to second element after post increment\n max=*ptr++;\n \n \/\/ Determining maximum value\n for(i=0;i\u0026lt;10;i++)\n {\n  if(*ptr \u0026gt; max)\n  {\n   max=*ptr;\n   ptr++;\n  }\n }\n \n \/\/ Printing maximum value\n printf(\"\\nMaximum value : %d\",max);\n \n getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\n\u003C\/pre\u003E\u003C\/div\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers1.html#p7\" name=\"p7\"\u003E7. Program to print sum of all the elements in 2D array using pointer\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\nint main()\n{\n \/\/ Declaring 2D array and initializing it\n int a[3][4]={{3,4,5,6},{5,6,7,8},{8,9,10,11}};\n \n \/\/ Declaring varaible sum\n int sum=0;\n \n \/\/ Declaring pointer variable\n int *ptr, *ptre;\n \n ptr=\u0026amp;a[0][0]; \/\/ points to address of first element\n ptre=ptr+12; \n \n \/\/ Calculating sum\n while(ptr\u0026lt;ptre)\n {\n  sum+=*ptr++;\n }\n \n \/\/ Displaying calculated sum\n printf(\"Sum of all elements : %d\",sum);\n \n getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\n\u003C\/pre\u003E\u003C\/div\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers1.html#p8\" name=\"p8\"\u003E8. Program to sort an array of elements using pointers\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\nint main()\n{\n\n \/\/ Declaring array and initializing it\n int a[]={5,6,3,4,5};\n\n \/\/ Declaring pointer variable *p, *q and temp=tempeorary that helps in swapping numbers\n int *p,*q,temp;\n\n \/\/ Declaring variable i, j to iterate loop\n int i,j;\n\n \/\/Displaying array elements\n printf(\"Array elements : \");\n for(i=0;i\u0026lt;5;i++)\n {\n  printf(\"%d \",a[i]);\n }\n printf(\"\\n\");\n \n \/\/ Pointing to the address of first element\n p=\u0026amp;a[0];\n \n \/\/ Performing sorting\n for(i=0;i\u0026lt;5;i++)\n {\n  for(j=i+1;j\u0026lt;5;j++)\n  {\n   \/\/ Swapping elements\n   if(*(p+i) \u0026gt; *(p+j))\n   {\n    temp=*(p+i);\n    *(p+i)=*(p+j);\n    *(p+j)=temp;\n   }\n  }\n }\n\n \/\/ Displaying sorted elements\n printf(\"Sorted elements : \");\n for(i=0;i\u0026lt;5;i++)\n {\n  printf(\"%d \",a[i]);\n }\n \n getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\n\u003C\/pre\u003E\u003C\/div\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers1.html#p9\" name=\"p9\"\u003E9. Program to sort string using pointers\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\nint main()\n{\n \/\/ Declaring variable str\n char str[50], *p;\n \n \/\/ Declaring variable i, j to iterate loop\n int i, j;\n \n \/\/ Declaring variable l=length, temp=tempeorary that helps in swapping\n int l=0, temp;\n \n \/\/ Inputing string\n printf(\"Enter any string : \");\n gets(str);\n \n p=\u0026amp;str[0];\n \n \/\/ finding length\n while(str[l]!='\\0')\n l++;\n \n \/\/ Performing sorting\n for(i=0;i\u0026lt;l;i++)\n {\n  for(j=i+1;j\u0026lt;l;j++)\n  {\n   \/\/ Swapping characters\n   if(*(p+i)\u0026gt;*(p+j))\n   {\n    temp=*(p+i);\n    *(p+i)=*(p+j);\n    *(p+j)=temp;\n   }\n  }\n }\n \n \/\/ Displaying sorted string\n printf(\"Sorted string : \\n\");\n p=\u0026amp;str[0];\n \n for(i=0;i\u0026lt;l;i++)\n {\n  printf(\"%c\\n\",*(p+i));\n }\n \n getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\n\u003C\/pre\u003E\u003C\/div\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers1.html#p10\" name=\"p10\"\u003E10. Program to search given element in an array using pointers\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\nint main()\n{\n\n \/\/ Declaring array and initializing it, *p=points to the address of first element\n int a[]={5,6,3,4,5}, *p;\n p=\u0026amp;a[0];\n \n \/\/ Declaring variable i = to iterate loop\n int i;\n \n \/* Declaring variable es = element to be searched, flag = to indicate \n if element is present or not *\/\n int es, flag=0;\n \n \/\/ Displaying array element\n printf(\"Array elements : \");\n for(i=0;i\u0026lt;5;i++)\n {\n  printf(\"%d \",*(p+i));\n }\n \n \/\/ Inputing element to be searched\n printf(\"\\nEnter element to be searched : \");\n scanf(\"%d\",\u0026amp;es);\n \n \/\/ Searching element\n for(i=0;i\u0026lt;5;i++)\n {\n  if(*(p+i)==es)\n  {\n   flag=1;\n   break;\n  }\n }\n \n \/\/ Displaying whether element found or not\n if(flag==1)\n printf(\"Element found \");\n \n else\n printf(\"Element not found \");\n \n getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\n\u003C\/pre\u003E\u003C\/div\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers1.html#p11\" name=\"p11\"\u003E11. Program to demonstrate the use of pointer to pointer\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\nint main()\n{\n int x,*p,**q;\n             \n    printf(\"\\nEnter a number : \");\n    scanf(\"%d\",\u0026amp;x);\n    \n    p=\u0026amp;x;\n    q=\u0026amp;p;\n    \n    printf(\"\\nValue of x=%d\",x);\n    printf(\"\\nValue of x through pointer=%d\",*p);\n    printf(\"\\nVal. of x through pointer to  pointer=%d\",**q);\n    printf(\"\\nValue of p=%u\",p);\n    printf(\"\\nValue of q=%u\",q);\n    printf(\"\\nAddres of p=%u\",q);\n     \n getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\u003C\/pre\u003E\u003C\/div\u003E\u003C\/div\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.comp-psyche.com\/feeds\/6794134224349899676\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers1.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/8285804830535272268\/posts\/default\/6794134224349899676"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/8285804830535272268\/posts\/default\/6794134224349899676"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers1.html","title":"C PROGRAMS : POINTERS"}],"author":[{"name":{"$t":"Mantu Kumar"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"0"}},{"id":{"$t":"tag:blogger.com,1999:blog-8285804830535272268.post-1916316238468921225"},"published":{"$t":"2014-01-29T06:48:00.000-08:00"},"updated":{"$t":"2014-04-16T01:03:09.050-07:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"C Programs"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Pointers"}],"title":{"type":"text","$t":"C PROGRAMS : POINTERS"},"content":{"type":"html","$t":"\u003Cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003E\u003Ctitle\u003EC PROGRAMS : POINTERS\u003C\/title\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers.html#p1\" name=\"p1\"\u003E1. Program to accept two numbers and print its address along with the numbers\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E# include \u0026lt;stdio.h\u0026gt;\n# include \u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\nint main( )\n{\n \/\/ Declaring variable a, b = two numbers\n int a, b;\n \n \/\/ Inputing two numbers\n printf(\"Enter first number : \");\n scanf(\"%d\",\u0026amp;a);\n \n printf(\"Enter first number : \");\n scanf(\"%d\",\u0026amp;b);\n \n \/\/ Printing address along with number\n printf(\"First number : %d, Address : %d\\n\",a, \u0026amp;a);\n printf(\"First number : %d, Address : %d\\n\",*(\u0026amp;a), \u0026amp;a);\n \n printf(\"Second number : %d, Address : %d\\n\",b, \u0026amp;b);\n printf(\"Second number : %d, Address : %d\",*(\u0026amp;b), \u0026amp;b);\n \n getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\n\u003C\/pre\u003E\u003C\/div\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers.html#p2\" name=\"p2\"\u003E2. Program to accept two numbers and print the sum of given two numbers by using pointers\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E# include \u0026lt;stdio.h\u0026gt;\n# include \u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\nint main( )\n{\n \/\/ Declaring variable a, b = two numbers\n int a, b;\n \n \/\/ Declaring variale s=sum\n int s=0;\n \n \/\/ Inputing two numbers\n printf(\"Enter first number : \");\n scanf(\"%d\",\u0026amp;a);\n \n \/\/ Inputing second number\n printf(\"Enter first number : \");\n scanf(\"%d\",\u0026amp;b);\n \n \/\/ Determining sum\n s=*(\u0026amp;a)+*(\u0026amp;b);\n \n \/\/ Printing sum\n printf(\"Sum = %d\",s);\n \n getch( ); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\n\u003C\/pre\u003E\u003C\/div\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers.html#p3\" name=\"p3\"\u003E3. Program to interchange two values using pointers\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\nint main()\n{\n \/\/ Declaring variable a, b for two values, swap to interchange value\n int a, b, swap;\n \n \/\/ Declaring pointer that holds address of two values\n int *c, *d;\n \n \/\/ Storing address\n c=\u0026amp;a;\n d=\u0026amp;b;\n \n \/\/ Inputing values\n printf(\"Enter first value a : \");\n scanf(\"%d\",\u0026amp;a);\n \n printf(\"Enter second value b : \");\n scanf(\"%d\",\u0026amp;b);\n \n \/\/ Printing original value\n printf(\"Original value : a = %d, b = %d\\n\",a, b);\n \n \/\/ Interchanging value\n swap=*c;\n *c=*d;\n *d=swap;\n \n \/\/ Printing interchanged value\n printf(\"Interchanged value : a = %d, b = %d \",a, b);\n  \n getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\n\u003C\/pre\u003E\u003C\/div\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers.html#p4\" name=\"p4\"\u003E4. Implement a function interchange() to interchange two values using pointers \u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\nint main()\n{\n \/\/ Declaring variable a, b for two values\n int a,b;\n\n \/\/ Inputing values\n printf(\"Enter first value a : \");\n scanf(\"%d\",\u0026amp;a);\n \n printf(\"Enter second value b : \");\n scanf(\"%d\",\u0026amp;b);\n \n \/\/ Printing original value\n printf(\"Original value : a = %d, b = %d\\n\",a, b);\n \n \/\/ Calling function interchange\n interchange(\u0026amp;a, \u0026amp;b);\n \n getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\n\nvoid interchange(int *x, int *y)\n\n{\n int swap;\n \n \/\/ Interchanging value\n swap=*x;\n *x=*y;\n *y=swap;\n \n \/\/ Printing interchanged value\n printf(\"Interchanged value : a = %d, b = %d \",*x, *y);\n}\u003C\/span\u003E\n\n\u003C\/pre\u003E\u003C\/div\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers.html#p5\" name=\"p5\"\u003E5. Program to sum all the elements of an array using pointer\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\nint main()\n{\n \/\/ Declaring array variable \"a\" of size 10 and initializing it\n int a[10]={21, -2, 4, 6, 9, 12, 43, 22, 4, 8}, sum=0;\n \n \/\/ Declaring pointer type variable pointing to the the base address i.e ( a[0] ) of array 'a'  \n int *ptr=a; \/\/ It is equivalent to : int *ptr; ptr=\u0026amp;a;\n \n \/\/ Declaring variable ptre = stores address of 11th element\n int *ptre;\n ptre = ptr+10;\n \n \/\/ Calculating sum\n while(ptr\u0026lt;ptre)\n {\n  sum+=*ptr++; \/\/ sum=sum + *ptr++\n }\n \n \/\/ Displaying calculated sum\n printf(\"Sum of all elements : %d \",sum);\n \n getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\n\n\u003C\/pre\u003E\u003C\/div\u003E\u003Cbr \/\u003E\n\u003C\/div\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.comp-psyche.com\/feeds\/1916316238468921225\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/8285804830535272268\/posts\/default\/1916316238468921225"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/8285804830535272268\/posts\/default\/1916316238468921225"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.comp-psyche.com\/2014\/01\/c-programs-pointers.html","title":"C PROGRAMS : POINTERS"}],"author":[{"name":{"$t":"Mantu Kumar"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"0"}},{"id":{"$t":"tag:blogger.com,1999:blog-8285804830535272268.post-7709750115090501216"},"published":{"$t":"2013-11-29T00:05:00.000-08:00"},"updated":{"$t":"2014-04-16T01:12:09.939-07:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Common Programming Error"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Learn C"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Pointers"}],"title":{"type":"text","$t":"COMMON PROGRAMMING ERRORS - POINTERS"},"content":{"type":"html","$t":"\u003Cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003E\u003Ctitle\u003ECOMMON PROGRAMMING ERRORS - POINTERS\u003C\/title\u003E\u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: left;\"\u003E\u003C\/div\u003E\u003Cul style=\"text-align: left;\"\u003E\u003Cli style=\"text-align: justify;\"\u003EThe \u003Cspan style=\"color: lime;\"\u003Easterisk(*)\u003C\/span\u003E notation used to declare pointer variables does not distribute to all variable names in a declaration. Each pointer must be declared with the\u003Cspan style=\"color: lime;\"\u003E *\u003C\/span\u003E prefixed to the name. Eg: \u003Cspan style=\"color: lime;\"\u003Eint *x,*y;\u003C\/span\u003E\u003C\/li\u003E\n\u003C\/ul\u003E\u003Cul style=\"text-align: left;\"\u003E\u003Cli style=\"text-align: justify;\"\u003EDereferencing a pointer that has not been properly initialized or that has not been assigned to point to a specific location in memory is an error. This could cause a \u003Cspan style=\"color: lime;\"\u003Efatal execution time error,\u003C\/span\u003E or it could accidently \u003Cspan style=\"color: lime;\"\u003Emodify important data\u003C\/span\u003E and allow the program to run to completion with\u003Cspan style=\"color: lime;\"\u003E incorrect result.\u003C\/span\u003E\u003C\/li\u003E\n\u003C\/ul\u003E\u003Cul style=\"text-align: left;\"\u003E\u003Cli style=\"text-align: justify;\"\u003EBeing unaware that a \u0026nbsp;function is expecting pointers as arguments for \u003Cspan style=\"color: lime;\"\u003Epass-by-reference\u003C\/span\u003E and\u003Cspan style=\"color: lime;\"\u003E passing arguments by value.\u003C\/span\u003E Some compilers take the values assuming they're pointers and dereference the values as pointers. At run time, \u003Cspan style=\"color: lime;\"\u003Ememory-access\u003C\/span\u003E \u003Cspan style=\"color: lime;\"\u003Eviolation\u003C\/span\u003E or \u003Cspan style=\"color: lime;\"\u003Esegmentation faults\u003C\/span\u003E are often generated. Other compilers catch the mismatch in types between arguments and parameters and generate error messages.\u003C\/li\u003E\n\u003C\/ul\u003E\u003Cul style=\"text-align: left;\"\u003E\u003Cli style=\"text-align: justify;\"\u003EUsing pointer arithmetic on a pointer that does not refer to an element in an array.\u003C\/li\u003E\n\u003C\/ul\u003E\u003Cul style=\"text-align: left;\"\u003E\u003Cli style=\"text-align: justify;\"\u003E\u003Cspan style=\"color: lime;\"\u003ESubtracting\u003C\/span\u003E or \u003Cspan style=\"color: lime;\"\u003Ecomparing\u003C\/span\u003E two pointers that do not refer to elements in the same array.\u003C\/li\u003E\n\u003C\/ul\u003E\u003Cul style=\"text-align: left;\"\u003E\u003Cli style=\"text-align: justify;\"\u003E\u003Cspan style=\"color: lime;\"\u003ERunning off\u003C\/span\u003E either end of an array when using \u003Cspan style=\"color: lime;\"\u003Epointer arithmetic.\u003C\/span\u003E\u003C\/li\u003E\n\u003C\/ul\u003E\u003Cul style=\"text-align: left;\"\u003E\u003Cli style=\"text-align: justify;\"\u003E\u003Cspan style=\"color: lime;\"\u003EAssigning pointer\u003C\/span\u003E of one type to a pointer of another type if neither is of type \u003Cspan style=\"color: lime;\"\u003Evoid *\u003C\/span\u003E is a \u003Cspan style=\"color: lime;\"\u003Esyntax error.\u003C\/span\u003E\u003C\/li\u003E\n\u003C\/ul\u003E\u003Cul style=\"text-align: left;\"\u003E\u003Cli style=\"text-align: justify;\"\u003E\u003Cspan style=\"color: lime;\"\u003EDereferencing\u003C\/span\u003E a \u003Cspan style=\"color: lime;\"\u003Evoid *\u003C\/span\u003E pointer is a syntax error.\u003C\/li\u003E\n\u003C\/ul\u003E\u003Cul style=\"text-align: left;\"\u003E\u003Cli style=\"text-align: justify;\"\u003EAttempting to \u003Cspan style=\"color: lime;\"\u003Emodify an array name\u003C\/span\u003E with\u003Cspan style=\"color: lime;\"\u003E pointer arithmetic\u003C\/span\u003E is a \u003Cspan style=\"color: lime;\"\u003Ecompilation error.\u003C\/span\u003E\u0026nbsp;\u003C\/li\u003E\n\u003C\/ul\u003E\u003Cdiv style=\"text-align: justify;\"\u003E\u003Cspan style=\"color: yellow;\"\u003EMore Informative Posts:\u003C\/span\u003E\u003C\/div\u003E\u003Cdiv style=\"text-align: justify;\"\u003E\u003Cul\u003E\u003Cli\u003E\u003Cspan style=\"color: yellow;\"\u003E\u003Ca href=\"http:\/\/www.comp-psyche.com\/2013\/11\/learn-C.html\"\u003EComplete List Of Learn C\u003C\/a\u003E\u003C\/span\u003E\u003C\/li\u003E\n\u003Cli\u003E\u003Ca href=\"http:\/\/www.comp-psyche.com\/2013\/11\/common-programming-error-complete-list.html\"\u003ECommon Programming Error - Complete List\u003C\/a\u003E\u003C\/li\u003E\n\u003Cli\u003E\u003Ca href=\"http:\/\/www.comp-psyche.com\/2013\/11\/common-programming-errors-structures.html\"\u003ECommon Programming Error - Structures\u003C\/a\u003E\u003C\/li\u003E\n\u003Cli\u003E\u003Ca href=\"http:\/\/www.comp-psyche.com\/2013\/11\/common-programming-error-file-handling.html\"\u003ECommon Programming Error - File Handling\u003C\/a\u003E\u003C\/li\u003E\n\u003C\/ul\u003E\u003C\/div\u003E\u003C\/div\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.comp-psyche.com\/feeds\/7709750115090501216\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.comp-psyche.com\/2013\/11\/common-programming-errors-pointers.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/8285804830535272268\/posts\/default\/7709750115090501216"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/8285804830535272268\/posts\/default\/7709750115090501216"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.comp-psyche.com\/2013\/11\/common-programming-errors-pointers.html","title":"COMMON PROGRAMMING ERRORS - POINTERS"}],"author":[{"name":{"$t":"Mantu Kumar"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"0"}}]}});