We cannot use constructors if we want that whenever a pointer is declared, it should be NULL. Am I right Sir?
if I declare student *head, *tail, where student is a class, can I make my pointers automatically make NULL using default constructor?

Recommended Answers

All 3 Replies

Pointers are built-in types, they don't have constructors per se. If you want your ppointers to be null, make them null explicitly.

student *head = 0;
student *tail = 0;

Assuming those pointers are members of another class then you can certainly use the default constructor to make them null.:

class foo {
public:
    foo(): head(0), tail(0) {}
private:
    student *head, *tail;
};

and how will I use this in main()?

The same way you use it in any function. main is just a function

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.