c change pointer value in function code example

Example 1: c programm pointer change in function

void foo(int** p) {     //*p p den allazei , *p **p allazei! deikse null //
      *p = NULL;  /* set pointer to null */
 }
 void foo2(int* p) {
      p = NULL;  /* makes copy of p and copy is set to null*/
 }

 int main() {
     int* k;
     foo2(k);   /* k unchanged */
     foo(&k);   /* NOW k == NULL */
 }

Example 2: c programm pointer change in function

int* change_adrs(int *q) //me return kai anathesh: p=returned kai synarthsh me mesa *kati=&x x=5;//
      {                  //xwris reference, by value.Epistrefei apla dieythynsh kathorismenh sthn synarthsh panta to 875002//
      int * otheraddess;
      q = otheraddress;
      return q; 
      }


int main()
{
 p=change_adrs(p);
 return 0;
}

Tags:

Misc Example