© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

10. When does a name clash occur?

Ans:

A name clash occurs when a name is defined in more than one place. For example., two different class libraries could give two different classes the same name. If you try to use many class libraries at the same time, there is a fair chance that you will be unable to compile or link the program because of name clashes

Ex 1: Find the output of the following program
void main()
{
            int a, *pa, &ra;
            pa = &a;
            ra = a;
            cout <<"a="<<
}


Ans:
            Compiler Error: 'ra',reference must be initialized


Explanation :

            Pointers are different from references. One of the main differences is that the pointers can be both initialized and assigned, whereas references can only be initialized. So this code issues an error.

Ex 2: Find the output of the following program ?

const int size = 5;
void print(int *ptr)
{
            cout<<PTR[0];
}
 
void print(int ptr[size])
{
            cout<<PTR[0];
}
 
void main()
{
            int a[size] = {1,2,3,4,5};
            int *b = new int(size);
            print(a);
            print(b);
}

Ans:
            Compiler Error : function 'void print(int *)' already has a body
 
Explanation:

            Arrays cannot be passed to functions, only pointers (for arrays, base addresses) can be passed. So the arguments int *ptr and int prt[size] have no difference as function arguments. In other words, both the functoins have the same signature and so cannot be overloaded.

SLogix Student Projects
bottom