I don't know what the "*" or "**"or "***" means.
could anyone help me please?

#include <iostream.h>
#include <complex.h>


#define PI 3.141592654

extern int phin,Ne;
extern double Lamda;
extern double ***TS;
extern double ***TF;

extern complex **d;
extern complex *bd;

Edited 4 Years Ago by sajaddehghan: n/a

In this case these line are declaring variables the * means pointer to so in

int* a;

This is read as a is a pointer to an int, that is a contains the memory location of an int variable.

int** b;

There are 2 * you read the pointer to twice, that is b is a pointer to a pointer to an int. b holds the memory location of an address that holds the memory location of an int.

int*** c;

c is a pointer to a pointer to a pointer to an int. On the whole I have rarely (if ever) seen code that dereferences this far (each * is 1 level of dereferencing) but it follows the same pattern.

The same applies to the variables declared in this code.

In this case these line are declaring variables the * means pointer to so in

int* a;

This is read as a is a pointer to an int, that is a contains the memory location of an int variable.

int** b;

There are 2 * you read the pointer to twice, that is b is a pointer to a pointer to an int. b holds the memory location of an address that holds the memory location of an int.

int*** c;

c is a pointer to a pointer to a pointer to an int. On the whole I have rarely (if ever) seen code that dereferences this far (each * is 1 level of dereferencing) but it follows the same pattern.

The same applies to the variables declared in this code.

Thank you.Your explanation is very complete and useful

A variable preceded by an asterisk * is a pointer. The asterisk is called the indirection operator and is used to dereference pointers.

As it's name suggests a pointer is a variable which points to a variable of a specific type. So all a pointer holds is the memory address of the variable in question.

So in your code *bd is a pointer to a complex variable, so it points to/stores the memory address of a complex variable.

If there is more than one asterisk, it means that there are further levels of indirection.
So **d is a pointer to a pointer to a complex value (in other words it points to another pointer, which points to a complex value).
And ***TS is a pointer to a pointer to pointer to a double value.
So it points to a pointer, which points to another pointer, which points to a double value.

I'm not sure I've explained particularly clearly, but here's a simple, contrived example to show you what I mean:

#include <iostream>
int main()
{
    int i=25;
    int *pI = &i; // points to i
    int **ppI = &pI; // points to pI
    int ***pppI = &ppI; // points to ppI

    // Now lets see what each pointer holds at each level of indirection:
    std::cout << "Address of pI: " << pI;
    std::cout << "\n1st level: " << *pI;

    std::cout << "\n\nAddress of ppI: " << ppI; 
    std::cout << "\n1st level: " << *ppI; 
    std::cout << "\n2nd level: " << **ppI;

    std::cout << "\n\nAddress of pppI: " << pppI;
    std::cout << "\n1st level: " << *pppI;
    std::cout << "\n2nd level: " << **pppI;
    std::cout << "\n3rd Level: " << ***pppI << std::endl;
    return 0;
}

Which should yield the following output:

Address of pI: 0xbf91ccd8
1st level: 25

Address of ppI: 0xbf91ccd4
1st level: 0xbf91ccd8
2nd level: 25

Address of pppI: 0xbf91ccd0
1st level: 0xbf91ccd4
2nd level: 0xbf91ccd8
3rd Level: 25

So you can see the levels of indirection for each pointer and exactly what each pointer is pointing to.

NOTE: The addresses output when you run the program will probably be different, but you should be able to see similar results.

EDIT: Damn.....Too slow! Sorry I went to make a cup of tea in the middle of composing that reply!

Edited 4 Years Ago by JasonHippy: n/a

This article has been dead for over six months. Start a new discussion instead.