Pointer passed through functions

I am writing a code that creates a deck of cards using a doubly linked list. One function, newDeck(), is made to create a new deck if the user wants. I don't have any problems creating the deck and it all seems to work fine, but when I run the whole program and a separate function needs to utilize the nodes in my deck, I get an error. Trying to find where there was a problem, I tried displaying the values of a card node in random parts of my code. At the end of the newDeck function, after the whole deck has been created, the card still displays correctly, yet when I return back to main immediately after newDeck has been called, I noticed that the values of my cards changed to either random values or they became null. I found this strange because in between the end of my newDeck function and at this point, there is no extra code so it doesn't seem as if there is any way the pointers could have been changed. Maybe It's because I don't have a complete understanding of pointers yet but is there any way that pointers can change values when returning from a function to main?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 newDeck(head, tail, n);  //this is how I call the function from main. 


void newDeck(Card* head, Card* tail, Card* n)  //this is my function body
{

	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 13; j++)
		{
			n = new Card;
			n->suit = (CardSuit)i;
			n->rank = (CardRank)j;
			n->prev = nullptr;
			n->next = nullptr;
			if (i + j == 0)
			{
				n->prev = NULL;
				head = n;
				tail = n;
				
			}
			else
			{
				n->prev = tail;
				tail->next = n;
				tail = n;
			}
			
			
		}
	}
	//at this point my head and tail pointer point to the first and last card as they should but as soon as you return back to main, the pointers suddenly have different values.
}
Those are by value parameters. Mere copies. You do need by reference parameters.

void newDeck(Card* & head, Card* & tail, Card* & n)
Wow, thank you so much. That clarifies a lot.
Topic archived. No new replies allowed.