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

C and C++ Interview Questions

20. What is a scope resolution operator?

Ans:
A scope resolution operator resolves scope ambiguity in cases where a base class and a derived class both define data member or function with the same name. Most generally a scope resolution operator is required when a data member is redefined by a derived class or an overriden method of the derived class wants to call the base class version of the same method.

Ex - 1: What will be printed as the result of the operation below:
main()
{
int x=10, y=15;
x = x++;
y = ++y;
printf(“%d %dn”,x,y);
}
Ans: 11, 16

Ex - 2: What will be printed as the result of the operation below:
main()
{
int a=0;
if(a==0)
printf(“Cisco Systemsn”);
printf(“Cisco Systemsn”);
}
Ans: Two lines with “Cisco Systems” will be printed.

Ex - 3: What is the output?

main()
{
int c=- -2;
printf("c=%d",c);
}
Ans: c=2;
Explanation:Here unary minus (or negation) operator is used twice. Same maths rules applies, ie. minus * minus= plus.
Note: However you cannot give like --2. Because -- operator can only be applied to variables as a decrement operator (eg., i--). 2 is a constant and not a variable.


SLogix Student Projects
bottom