gdata.io.handleScriptLoaded({"version":"1.0","encoding":"UTF-8","feed":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$georss":"http://www.georss.org/georss","xmlns$thr":"http://purl.org/syndication/thread/1.0","xmlns$blogger":"http://schemas.google.com/blogger/2008","id":{"$t":"tag:blogger.com,1999:blog-8285804830535272268"},"updated":{"$t":"2023-07-30T02:11:08.392-07:00"},"category":[{"term":"C Programs"},{"term":"Pointers"},{"term":"string"},{"term":"Array"},{"term":"Learn C"},{"term":"Fundamental"},{"term":"Pattern"},{"term":"control sturctures"},{"term":"searching and sorting"},{"term":"recursion"},{"term":"List of C Programs"},{"term":"Structures"},{"term":"C Turbo Compiler"},{"term":"File Handling"},{"term":"Contents"},{"term":"Common Programming Error"},{"term":"functions"},{"term":"Dynamic memory allcation"}],"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.blogger.com/feeds/8285804830535272268/posts/default/-/Pointers?alt\u003djson-in-script\u0026max-results\u003d50"},{"rel":"self","type":"application/atom+xml","href":"https://www.blogger.com/feeds/8285804830535272268/posts/default/-/Pointers?alt\u003djson-in-script\u0026max-results\u003d50"},{"rel":"alternate","type":"text/html","href":"http://www.comp-psyche.com/search/label/Pointers"},{"rel":"hub","href":"http://pubsubhubbub.appspot.com/"}],"author":[{"name":{"$t":"Mantu Kumar"},"uri":{"$t":"https://www.blogger.com/profile/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"35","height":"35","src":"//www.blogger.com/img/blogger_logo_round_35.png"}}],"generator":{"version":"7.00","uri":"https://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\u003d\"ltr\" style\u003d\"text-align: left;\" trbidi\u003d\"on\"\u003e\u003ctitle\u003eC PROGRAMS : POINTERS\u003c/title\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-pointers1.html#p6\" name\u003d\"p6\"\u003e6. Program to find maximum element of an array of elements using pointer\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\nint main()\n{\n // Declaring array variable \"a\" of size 10, i\u003dto iterate loop, max\u003dmaximum 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\u003da; // It is equivalent to : int *ptr; ptr\u003d\u0026amp;a;\n \n // Inputing array elements\n printf(\"Enter 10 elements in an array : \");\n for(i\u003d0;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\u003d*ptr++;\n \n // Determining maximum value\n for(i\u003d0;i\u0026lt;10;i++)\n {\n  if(*ptr \u0026gt; max)\n  {\n   max\u003d*ptr;\n   ptr++;\n  }\n }\n \n // Printing maximum value\n printf(\"\\nMaximum value : %d\",max);\n \n getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n return 0;\n}\u003c/span\u003e\n\u003c/pre\u003e\u003c/div\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-pointers1.html#p7\" name\u003d\"p7\"\u003e7. Program to print sum of all the elements in 2D array using pointer\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\nint main()\n{\n // Declaring 2D array and initializing it\n int a[3][4]\u003d{{3,4,5,6},{5,6,7,8},{8,9,10,11}};\n \n // Declaring varaible sum\n int sum\u003d0;\n \n // Declaring pointer variable\n int *ptr, *ptre;\n \n ptr\u003d\u0026amp;a[0][0]; // points to address of first element\n ptre\u003dptr+12; \n \n // Calculating sum\n while(ptr\u0026lt;ptre)\n {\n  sum+\u003d*ptr++;\n }\n \n // Displaying calculated sum\n printf(\"Sum of all elements : %d\",sum);\n \n getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n return 0;\n}\u003c/span\u003e\n\u003c/pre\u003e\u003c/div\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-pointers1.html#p8\" name\u003d\"p8\"\u003e8. Program to sort an array of elements using pointers\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\nint main()\n{\n\n // Declaring array and initializing it\n int a[]\u003d{5,6,3,4,5};\n\n // Declaring pointer variable *p, *q and temp\u003dtempeorary 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\u003d0;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\u003d\u0026amp;a[0];\n \n // Performing sorting\n for(i\u003d0;i\u0026lt;5;i++)\n {\n  for(j\u003di+1;j\u0026lt;5;j++)\n  {\n   // Swapping elements\n   if(*(p+i) \u0026gt; *(p+j))\n   {\n    temp\u003d*(p+i);\n    *(p+i)\u003d*(p+j);\n    *(p+j)\u003dtemp;\n   }\n  }\n }\n\n // Displaying sorted elements\n printf(\"Sorted elements : \");\n for(i\u003d0;i\u0026lt;5;i++)\n {\n  printf(\"%d \",a[i]);\n }\n \n getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n return 0;\n}\u003c/span\u003e\n\u003c/pre\u003e\u003c/div\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-pointers1.html#p9\" name\u003d\"p9\"\u003e9. Program to sort string using pointers\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"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\u003dlength, temp\u003dtempeorary that helps in swapping\n int l\u003d0, temp;\n \n // Inputing string\n printf(\"Enter any string : \");\n gets(str);\n \n p\u003d\u0026amp;str[0];\n \n // finding length\n while(str[l]!\u003d'\\0')\n l++;\n \n // Performing sorting\n for(i\u003d0;i\u0026lt;l;i++)\n {\n  for(j\u003di+1;j\u0026lt;l;j++)\n  {\n   // Swapping characters\n   if(*(p+i)\u0026gt;*(p+j))\n   {\n    temp\u003d*(p+i);\n    *(p+i)\u003d*(p+j);\n    *(p+j)\u003dtemp;\n   }\n  }\n }\n \n // Displaying sorted string\n printf(\"Sorted string : \\n\");\n p\u003d\u0026amp;str[0];\n \n for(i\u003d0;i\u0026lt;l;i++)\n {\n  printf(\"%c\\n\",*(p+i));\n }\n \n getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n return 0;\n}\u003c/span\u003e\n\u003c/pre\u003e\u003c/div\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-pointers1.html#p10\" name\u003d\"p10\"\u003e10. Program to search given element in an array using pointers\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\nint main()\n{\n\n // Declaring array and initializing it, *p\u003dpoints to the address of first element\n int a[]\u003d{5,6,3,4,5}, *p;\n p\u003d\u0026amp;a[0];\n \n // Declaring variable i \u003d to iterate loop\n int i;\n \n /* Declaring variable es \u003d element to be searched, flag \u003d to indicate \n if element is present or not */\n int es, flag\u003d0;\n \n // Displaying array element\n printf(\"Array elements : \");\n for(i\u003d0;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\u003d0;i\u0026lt;5;i++)\n {\n  if(*(p+i)\u003d\u003des)\n  {\n   flag\u003d1;\n   break;\n  }\n }\n \n // Displaying whether element found or not\n if(flag\u003d\u003d1)\n printf(\"Element found \");\n \n else\n printf(\"Element not found \");\n \n getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n return 0;\n}\u003c/span\u003e\n\u003c/pre\u003e\u003c/div\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-pointers1.html#p11\" name\u003d\"p11\"\u003e11. Program to demonstrate the use of pointer to pointer\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"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\u003d\u0026amp;x;\n    q\u003d\u0026amp;p;\n    \n    printf(\"\\nValue of x\u003d%d\",x);\n    printf(\"\\nValue of x through pointer\u003d%d\",*p);\n    printf(\"\\nVal. of x through pointer to  pointer\u003d%d\",**q);\n    printf(\"\\nValue of p\u003d%u\",p);\n    printf(\"\\nValue of q\u003d%u\",q);\n    printf(\"\\nAddres of p\u003d%u\",q);\n     \n getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"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":"https://www.blogger.com/profile/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"35","height":"35","src":"//www.blogger.com/img/blogger_logo_round_35.png"}}],"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\u003d\"ltr\" style\u003d\"text-align: left;\" trbidi\u003d\"on\"\u003e\u003ctitle\u003eC PROGRAMS : POINTERS\u003c/title\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-pointers.html#p1\" name\u003d\"p1\"\u003e1. Program to accept two numbers and print its address along with the numbers\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e# include \u0026lt;stdio.h\u0026gt;\n# include \u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\nint main( )\n{\n // Declaring variable a, b \u003d 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\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n return 0;\n}\u003c/span\u003e\n\u003c/pre\u003e\u003c/div\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-pointers.html#p2\" name\u003d\"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\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e# include \u0026lt;stdio.h\u0026gt;\n# include \u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\nint main( )\n{\n // Declaring variable a, b \u003d two numbers\n int a, b;\n \n // Declaring variale s\u003dsum\n int s\u003d0;\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\u003d*(\u0026amp;a)+*(\u0026amp;b);\n \n // Printing sum\n printf(\"Sum \u003d %d\",s);\n \n getch( ); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n return 0;\n}\u003c/span\u003e\n\u003c/pre\u003e\u003c/div\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-pointers.html#p3\" name\u003d\"p3\"\u003e3. Program to interchange two values using pointers\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"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\u003d\u0026amp;a;\n d\u003d\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 \u003d %d, b \u003d %d\\n\",a, b);\n \n // Interchanging value\n swap\u003d*c;\n *c\u003d*d;\n *d\u003dswap;\n \n // Printing interchanged value\n printf(\"Interchanged value : a \u003d %d, b \u003d %d \",a, b);\n  \n getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n return 0;\n}\u003c/span\u003e\n\u003c/pre\u003e\u003c/div\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-pointers.html#p4\" name\u003d\"p4\"\u003e4. Implement a function interchange() to interchange two values using pointers \u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"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 \u003d %d, b \u003d %d\\n\",a, b);\n \n // Calling function interchange\n interchange(\u0026amp;a, \u0026amp;b);\n \n getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"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\u003d*x;\n *x\u003d*y;\n *y\u003dswap;\n \n // Printing interchanged value\n printf(\"Interchanged value : a \u003d %d, b \u003d %d \",*x, *y);\n}\u003c/span\u003e\n\n\u003c/pre\u003e\u003c/div\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-pointers.html#p5\" name\u003d\"p5\"\u003e5. Program to sum all the elements of an array using pointer\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\nint main()\n{\n // Declaring array variable \"a\" of size 10 and initializing it\n int a[10]\u003d{21, -2, 4, 6, 9, 12, 43, 22, 4, 8}, sum\u003d0;\n \n // Declaring pointer type variable pointing to the the base address i.e ( a[0] ) of array 'a'  \n int *ptr\u003da; // It is equivalent to : int *ptr; ptr\u003d\u0026amp;a;\n \n // Declaring variable ptre \u003d stores address of 11th element\n int *ptre;\n ptre \u003d ptr+10;\n \n // Calculating sum\n while(ptr\u0026lt;ptre)\n {\n  sum+\u003d*ptr++; // sum\u003dsum + *ptr++\n }\n \n // Displaying calculated sum\n printf(\"Sum of all elements : %d \",sum);\n \n getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"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":"https://www.blogger.com/profile/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"35","height":"35","src":"//www.blogger.com/img/blogger_logo_round_35.png"}}],"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\u003d\"ltr\" style\u003d\"text-align: left;\" trbidi\u003d\"on\"\u003e\u003ctitle\u003eCOMMON PROGRAMMING ERRORS - POINTERS\u003c/title\u003e\u003cbr /\u003e\n\u003cdiv style\u003d\"text-align: left;\"\u003e\u003c/div\u003e\u003cul style\u003d\"text-align: left;\"\u003e\u003cli style\u003d\"text-align: justify;\"\u003eThe \u003cspan style\u003d\"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\u003d\"color: lime;\"\u003e *\u003c/span\u003e prefixed to the name. Eg: \u003cspan style\u003d\"color: lime;\"\u003eint *x,*y;\u003c/span\u003e\u003c/li\u003e\n\u003c/ul\u003e\u003cul style\u003d\"text-align: left;\"\u003e\u003cli style\u003d\"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\u003d\"color: lime;\"\u003efatal execution time error,\u003c/span\u003e or it could accidently \u003cspan style\u003d\"color: lime;\"\u003emodify important data\u003c/span\u003e and allow the program to run to completion with\u003cspan style\u003d\"color: lime;\"\u003e incorrect result.\u003c/span\u003e\u003c/li\u003e\n\u003c/ul\u003e\u003cul style\u003d\"text-align: left;\"\u003e\u003cli style\u003d\"text-align: justify;\"\u003eBeing unaware that a \u0026nbsp;function is expecting pointers as arguments for \u003cspan style\u003d\"color: lime;\"\u003epass-by-reference\u003c/span\u003e and\u003cspan style\u003d\"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\u003d\"color: lime;\"\u003ememory-access\u003c/span\u003e \u003cspan style\u003d\"color: lime;\"\u003eviolation\u003c/span\u003e or \u003cspan style\u003d\"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\u003d\"text-align: left;\"\u003e\u003cli style\u003d\"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\u003d\"text-align: left;\"\u003e\u003cli style\u003d\"text-align: justify;\"\u003e\u003cspan style\u003d\"color: lime;\"\u003eSubtracting\u003c/span\u003e or \u003cspan style\u003d\"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\u003d\"text-align: left;\"\u003e\u003cli style\u003d\"text-align: justify;\"\u003e\u003cspan style\u003d\"color: lime;\"\u003eRunning off\u003c/span\u003e either end of an array when using \u003cspan style\u003d\"color: lime;\"\u003epointer arithmetic.\u003c/span\u003e\u003c/li\u003e\n\u003c/ul\u003e\u003cul style\u003d\"text-align: left;\"\u003e\u003cli style\u003d\"text-align: justify;\"\u003e\u003cspan style\u003d\"color: lime;\"\u003eAssigning pointer\u003c/span\u003e of one type to a pointer of another type if neither is of type \u003cspan style\u003d\"color: lime;\"\u003evoid *\u003c/span\u003e is a \u003cspan style\u003d\"color: lime;\"\u003esyntax error.\u003c/span\u003e\u003c/li\u003e\n\u003c/ul\u003e\u003cul style\u003d\"text-align: left;\"\u003e\u003cli style\u003d\"text-align: justify;\"\u003e\u003cspan style\u003d\"color: lime;\"\u003eDereferencing\u003c/span\u003e a \u003cspan style\u003d\"color: lime;\"\u003evoid *\u003c/span\u003e pointer is a syntax error.\u003c/li\u003e\n\u003c/ul\u003e\u003cul style\u003d\"text-align: left;\"\u003e\u003cli style\u003d\"text-align: justify;\"\u003eAttempting to \u003cspan style\u003d\"color: lime;\"\u003emodify an array name\u003c/span\u003e with\u003cspan style\u003d\"color: lime;\"\u003e pointer arithmetic\u003c/span\u003e is a \u003cspan style\u003d\"color: lime;\"\u003ecompilation error.\u003c/span\u003e\u0026nbsp;\u003c/li\u003e\n\u003c/ul\u003e\u003cdiv style\u003d\"text-align: justify;\"\u003e\u003cspan style\u003d\"color: yellow;\"\u003eMore Informative Posts:\u003c/span\u003e\u003c/div\u003e\u003cdiv style\u003d\"text-align: justify;\"\u003e\u003cul\u003e\u003cli\u003e\u003cspan style\u003d\"color: yellow;\"\u003e\u003ca href\u003d\"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\u003d\"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\u003d\"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\u003d\"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":"https://www.blogger.com/profile/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"35","height":"35","src":"//www.blogger.com/img/blogger_logo_round_35.png"}}],"thr$total":{"$t":"0"}}]}});