C - Tips

1) ++*ptr: incrments what ptr points to
     (*ptr)++ : The parentheses are necessary in this last example; without them, the expression would increment ip instead of what it points to, because unary operators like * and ++ associate right to left.

2)   int *ip,*iq;
       iq = ip;
      copies the contents of ip into iq, thus making iq point to whatever ip pointed to.

3) A[i] = *(a+i);
    int *pa,a[10];
   There is one difference between an array name and a pointer that must be kept in mind. A pointer is a variable, so pa=a and pa++ are legal. But an array name is not a variable; constructions like a=pa and a++ are illegal.

4)  char amessage[] = "now is the time"; /* an array */
      char *pmessage = "now is the time"; /* a pointer */
5) Big endian: Most significant byte at lowest address
      Little endian: Least significant byte at lowest address.
         0X12345678
         BE: 12 34 56 78
         LE: 78 56 34 12
6) Using call by reference: we can make a function to return more than one value from function.
7) Arithmetic operation cannot be performed on void pointer.
8) int *s;
    *++s = increments the address
    ++*s = increments the value
    (*++s)++ = increments the address and then value
    (*s)++ = increments the value

No comments:

Post a Comment