1

The * symbol is used for three different purposes

  1. multiplication
  2. Pointer declaration
  3. Pointer dereferencing.

Why designers of C kept this notation? In other words, wouldn't it be nice if there was special notation for pointer declaration and dereferencing? I think if there would have been special symbol or notation lots of confusion doesn't arise. Isn't it? If there were special notations for pointer declaration and dereferencing wouldn't it also make easier to understand pointer and associated operations easier?

I was reading this Why does C use the asterisk for pointers?. The 1st answer says that:

Because memory is a linear array, it is possible to interpret the value in a cell as an index in this array, and BCPL supplies an operator for this purpose. In the original language it was spelled rv, and later !, while B uses the unary *. Thus, if p is a cell containing the index of (or address of), or pointer to) another cell, *p refers to the contents of the pointed-to cell, either as a value in an expression or as the target of an assignment.
From The Development of the C Language

So, yes I know that C derived from B. But is it true that C was designed to be compatible with B as like C++ is compatible with C? Is it just for the compatibility reasons between B and C language to use * operator for pointer declaration and dereferencing ?

Consider following simple program.

#include <stdio.h>
int mul(int **a);
int main()
{
    int a=9;
    int* b=&a;
    a=mul(&b);
    printf("multiplication is %i",a);
    return 0;
}
int mul(int **a)
{
    int ans=**a*3;    // doesn't it looks ugly, confusing???
    return ans;
}
Destructor
  • 174
  • 1
  • 10

0 Answers0