DEV Community

Cover image for Can You Guess the output?? ;)
Vishal Ahirwar
Vishal Ahirwar

Posted on

Can You Guess the output?? ;)

#include <iostream>
#include <signal.h>
#define m_sig signal(SIGSEGV, sig_memory);
void sig_memory(int code)
{
    std::cout << "something went wrong!\n";
    exit(0);
};

class Test
{
private:
    Test();
    int data;

public:
    Test(const int &value) : data(value){};
    int get_data() const { return this->data; };
    void set_data(const int &value);
};
void Test::set_data(const int &value)
{
    this->data = value;
};
#define ONE
template <typename T>
void print_pointer(const T *const p)
{
    if (p == nullptr)
    {
         std::cout << "you are passing null pointer to argument!\n";
         return;
     };
     std::cout << *p << "\n";
}
int main()
{
    m_sig

#ifndef ONE
        Test test1 = 45;
#else
        Test test1(90);
#endif
    std::cout << test1.get_data() << '\n';
    int *const ptr = 0;
    *ptr = 56;
    print_pointer(ptr);
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
amarjeeth123 profile image
amarjeeth123

90
something went wrong!