-2

I am learning C and I have difficulty in understanding difference between two statements which are pointers

double **X;

and

double** X;

Are both same?

Also one more question.

When do we actually get a situtation to use pointer to a pointer like above **X

ashiquzzaman33
  • 5,781
  • 5
  • 31
  • 42
noob man
  • 1
  • 1
  • 2
    Those two variable declarations mean the same thing. The `*` is the dereference operator, so it reads *the value that (the value that `X` points at) points at is a double.* – aioobe Sep 27 '15 at 19:01
  • 1
    This one `double** X;` can be confusing in my opinion and it's ugly. Other than that, why would they be different? And `double * * X` would be the same too or `double**x`. White spaces are not really very relevant for this, they are good to add clarity to the code and I encourage you to use them as much as possible to make the code clear, to distinguish tokens from each other for the human eye, but are otherwise useless. – Iharob Al Asimi Sep 27 '15 at 19:04
  • @zenith I don't think that's a very good duplicate. I found this one just by googling. – PC Luddite Sep 27 '15 at 19:09
  • Thanks aioobe and iharob for the explanation. It is clear now – noob man Sep 27 '15 at 19:12
  • do i delete this question since it is duplicate...? – noob man Sep 27 '15 at 19:20

1 Answers1

0

Both of those examples are the same. It defines a type of X as a pointer to pointer to double.

An array is a continuous fragment of memory that you access by pointer to it's first element. If you have an array of arrays then type of it is 'whatever element type is'**.

For example strings are arrays of chars, terminated by '\0' byte. So array of string is of type char**

Example usage is really common thing, main() function, that can be declared as follows

int main(int argc, char** argv)

so argv is an array of strings that are arguments or your program, argc is its' length.

Łukasz
  • 8,555
  • 2
  • 28
  • 51