How do i go about printing the "info" value of the "Body", [ cout<<Body->info;] is giving me a weird value

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// First_VB_Prog.cpp : Defines the entry point for the console application.
//

#include <iostream>

using namespace std;

//Simple Linked List composing of a "Body" , "Head" and a "Tail"

struct nodeType
{

    int info;
    int info_2;
    nodeType *link;
};

class linkedList
{

public:
    linkedList()
    {
        Head = NULL;
    }

    nodeType* addHead()
    {

        Head = new nodeType;
        return Head;
    }
private:

    nodeType *Head;
};

int main()
{

//declaring Nodes:

    nodeType *Body;
    Body = new nodeType;
    nodeType *Tail;
    Tail = new nodeType;

    int num;

//Linking Nodes

    linkedList listt;

    Body->info = num; //accessing info on Body Node
    listt.addHead()->link = Body;	//linking OR joing the head to the body Node

    Body->link = Tail; //linking OR joing the body to the  TailNode
    Tail->info = num;  //accessing info on Tail Node

    cout<<Body->info;
}
You didn't initialize num.
wow, i am such a noob, thanks EssGeEich (1559)
The number after my nick means how many posts i've written up until this moment (In fact, my nick is just "EssGeEich").
Right now, it should be higher than the last time you checked.
You, too, have a number right there, which means how many posts you've written.

Anyways, it's not a big problem, I just needed a fast look to see you had nothing initialized to a specific number (besides the pointers).
Topic archived. No new replies allowed.