ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories >> Software >> Programming-Languages
 
  C (720)  C++ (451)  Delphi (508)  Programming-Languages-AllOther (219)
 


 

Back to Questions Page
 
Question
can anyone please tell me wat is backlogs... i was looking 
for the job openings where i read this.. eligibility 
criteria minimum 70% in degree without backlogs. is that 
arrear.. if so is it standing arrear or history of 
arrears... please help me...
Rank Answer Posted By  
 Question Submitted By :: Flethitia
I also faced this Question!!   © ALL Interview .com
Answer
Backlogs means standing arrears
 
0
Jainu
 
 
Answer
backlog means passing subjects in first attempt. Without any
subjects pending
 
0
Tushar
 
 
Question
What is the Advantage of Interface over the Inheritance in 
OOPS?
Rank Answer Posted By  
 Question Submitted By :: Phani Kumar S
I also faced this Question!!   © ALL Interview .com
Answer
1. Provides flexibility in implementing the operations for 
the derived classes.

2. Avoid conflicts when more than one interfaces are 
derived in a class.

I will club some more later...
 
0
Mms Zubeir
 
 
 
Answer
1)Interface totally keeps away that implementation 
knowledge from client.
2)It supports us to change their behaviour dynamically.It 
means that, it will act depends on dynamic specilization(or 
substitution).
3)This gives very good abstraction about the object to 
client.
4)It avoids client broken, even developer made some changes 
on implimentation or add new specilization(new 
implementation).
5)So it gives open way to extend and implementation.
 
0
Iyappan_protech
 
 
Question
What is external and internal variables
What is dynamic memory allocation
what is storage classes in C
Rank Answer Posted By  
 Question Submitted By :: Ang
I also faced this Question!!   © ALL Interview .com
Answer
Dynamic allocation is a pretty unique feature to C (amongst
high level languages). It enables us to create data types
and structures of any size and length to suit our programs
need within the program. 

storage classes

auto 
register 
static 
extern 
typedef
 
0
Rekha
 
 
Answer
External variable -- Variable that one going to be access
from another source file.Have life cycle for complete project.

Internal variable -- variable that one have the life cycle
for the particular  block.

Dynamic memory allocation --Allocation of memory during RUN
time.

Storage Class -- 

Automatic : by default 
Register : Use to access registers of CPU.If register is not
free than work as automatic.
Static : Have life cycle for whole project but access only
with in the initialized function block.Once initialized.
extern : above
 
0
Ravi Saini
 
 
Question
Explain following declaration
int *P(void); 
and
int (*p)(char *a);
Rank Answer Posted By  
 Question Submitted By :: Anil Rai
I also faced this Question!!   © ALL Interview .com
Answer
int *p(void) - says this is function with null parameter 
and returns a pointer to an integer.

int (*p)(char *a) - says this is function with a pointer to 
a char a as  parameter and returns a pointer to an integer.
 
0
Tibu
 
 
Answer
int* p(void) means p is a function that takes no argument a
return a pointer to integer.
int (*p)(char*a) means that p is a pointer to function that
take character pointer as argument and return an integer.
 
0
Vijay
 
 
Question
what is the difference between class and object?
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
Class : class ia a blueprint or prototype from which object 
are created
Object: Object is a Software bundles of related state and 
behavior.
 
0
Rahul
 
 
Answer
class:class is an abstract data type in which both Member 
functions and member variable are declared that means  
aclass is userdefined data type in which we will be able to 
declare both methods and variable.
object : Object is an Instance of the class.The class is a 
valid one when object is created.
For one class we will have more number of Objects.
declaration of class in 
class classname 
{
public:
Member variables;
Member functions();
protected:
Member variables;
Member functions();
Private:
Member variables;
Member functions();
};
Declaration of Objects:
class classname allaisname;
here allias name is nothing but objectname.
if we want to get the data from that particular we have to 
use objects.
objectname.functionname();
 
0
Jayasrinivas.donavalli
 
 
Answer
Class is just a template. It does not allocate memory 
space. When instantiate the object, allocates the memory 
space
 
5
S.jagadeeswari
 
 
Question
logic for generating all the combinations of the any number
of given letters.
ex:::::::::
if a,b,c,d are given the o/p should be
abcd,dcba,dbac,bcad,................
4*3*2*1 combinations............
Rank Answer Posted By  
 Question Submitted By :: Shiva034
This Interview Question Asked @   Infosys
I also faced this Question!!   © ALL Interview .com
Answer
#include <stdio.h>

void permute ( char* strptr, int start, int length )
{
	int count1;
	int count2;
	int temp;

	for ( count1 = start; count1 < length - 1; 
++count1 ) {
		for ( count2 = count1 + 1; count2 < length; 
++count2 ) {
			temp = strptr [ count1 ]; strptr [ 
count1 ] = strptr [ count2 ]; strptr [ count2 ] = temp;
			permute ( strptr, count1 + 1, 
length );
			temp = strptr [ count1 ]; strptr [ 
count1 ] = strptr [ count2 ]; strptr [ count2 ] = temp;
		}
	}
	printf ( "\n%s", strptr );
}

int main ( int argc, char* argv [] )
{
	char str[] = "abcd";

	permute ( str, 0, ( strlen ( str ) ) );

	return 0;	
}
 
0
Abdur Rab
 
 
Question
code snippet for creating a pyramids triangle
ex

     1
   2   2
 3   3   3
Rank Answer Posted By  
 Question Submitted By :: Shiva034
I also faced this Question!!   © ALL Interview .com
Answer
void main()  

 { 
 int n,i,j;
 printf("enter the num of rows\t:");
 scanf("%d",&n);
 
 for(i=1;i<=n;i++)
 {
	 for(int k=0;k<n-i;k++)
	 printf(" ");  
	 for(j=1;j<=i;j++)
		 printf("%d ",i);
	 printf("\n");
 }
}
 
0
Rajesh Kamar S
 
 
Answer
A SMALL IMPLEMENTATION OF POINTERS
 
#include<stdio.h>
#include<conio.h>
void main()
{
int n,*p,*q;
printf("enter the number of lines :");
scanf("%d",&n);
for(int i=1,p=&i;*p<=n;*p++)
{
printf("\n");
  for(int j=1,q=&j;*q<=*p;*q++)
{
printf("%d",*p);
printf(" ");
}
}
getch();
}
 
0
Vignesh1988i
 
 
Question
Given three sides of a triangle. Write the Program to
determine whether the triangle is :
1) Invalid
2) Right Angled
3) Isoscales
4) Equilateral
5) Not Special

An Isoscales right angled triangle should be taken as a
Right Angled Triangle
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   Goldman-Sachs
I also faced this Question!!   © ALL Interview .com
Answer
if a, b and c are the three sides of a triangle, then a + b > c
if this is not satisfied, then its not a valid triangle.

To check for right angle, use Pythagoras theorem. Assume
that the longest side is the hypotenuse.

Issosless and Equilateral can be found by simply comparing
the sides.
 
0
Sunil
 
 
Answer
One should check for valid sides also. Side values dhould 
be greated than ZERO.

Here is the correct routine: 
	public static String checkTriangle(int[] 
triangleSide){
		boolean validTriangle = false;
		boolean validSides	= true;
		String result = "NOT VALID TRIANGLE";

		for(int side: triangleSide)
			if(side <= 0)
				validSides	= false;
		
		if(validSides){
			for(int count= 0; count< 3 ; 
count++){
				if(((triangleSide[count%3] 
+ triangleSide[(count+1)%3]) > triangleSide[(count+2)%3]))
					validTriangle = 
true;
			}
	
			if(validTriangle){
				if( triangleSide[0] == 
triangleSide[1] && triangleSide[2] == triangleSide[1])
					result 
= "EQUILATERAL";
				else{
					for(int count= 0; 
count< 3 ; count++){
						
						if( ( 
triangleSide[count%3] * triangleSide[count%3] + triangleSide
[(count+1)%3] * triangleSide[(count+1)%3]) == (triangleSide
[(count+2)%3] * triangleSide[(count+2)%3])){
						
	result = "RIGHANGLED";
						
	break;
						}else
							if
((triangleSide[count%3] == triangleSide[(count+1)%3]))
							
	result = "ISOSCALAUS";
					}
				}
				if("NOT VALID 
TRIANGLE".equals(result))
					result = "NOT 
SPECIAL";
					
			}
		}
		
		System.out.println(result);
		return result;
	}
 
0
Giri
 
 
Question
Write a Pseudo Code to fins the LCM of two given numbers
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   Goldman-Sachs
I also faced this Question!!   © ALL Interview .com
Answer
#include <iostream>
using namespace std;
int main()
{
	int x,y,z;
	cout<<"Enter First Integer:";
	cin>>x;
	cout<<"\nEnter Second Integer:";
	cin>>y;
	z=1;
	while(x/z==1 && y/z==1)
	{
		z=x/y;
		cout<<"The LCM of Both Numbers is:"<<z;
	}
	return 0;
}
 
0
Shailendra
 
 
Question
How would you stop a class from class from being derived or 
inherited?The constructer should not be Private,as object 
instantiation should be allowed.
Rank Answer Posted By  
 Question Submitted By :: Ananya Mittal
I also faced this Question!!   © ALL Interview .com
Answer
make destructor private. Derived class would not be able to
access it, and compiler will produce error, when instance of
derived class is deallocated.
 
0
Boriska
 
 
Answer
Use virtual class concept
 
0
Duke
 
 
Answer
sorry pa i can't understand any answer from ur points,i 
think u r just copy down the answers from the book.you have 
any other idea means plz tell me .i am very confused
 
0
Geetha
 
 
Answer
All the answers above are wrong. Guys, Don't provide some 
junk answers! It may be misinterpretted by someone who has 
less knowledge about the subject.
 
0
Mms Zubeir
 
 
Answer
OK, here is the piece of code which illustrates the concept 
=======================================================
class Base
{
private :
	char _id;
	~Base() {};
public :
	Base(char id='0') : _id(id) {};
	static Base* CreateBase(char id) { return new Base(id); }
	static void DestroyBase(Base* ptr) { delete ptr; }
};

/**/
class Derived : public Base
{
public :
	Derived(char id='1') : Base(id) {};
	~Derived() {};
};
/**/

int main(int argc, char** argv)
{

	Base* pb = Base::CreateBase('B');
	Base::DestroyBase(pb);
        return 0;
}
=================================================

I should have added that since Base class declares
destructor private, it cannot be instantiated directly
either, but I though it is kinda self-evident. My apologies
- just typed quick answer, describing a concept. 

So here you go : you need static create/destroy functions,
declared within the scope of the Base class (or friend
functions, declared globally).

Now the major point : no matter how you try, declaration of
class Derived will not pass compilation - unless you define
similar  create/destroy methods for class Derived within
Base class scope - which you, as a designer, choose not to
do. Here is the compiler error, produced at line with "void
Derived::~Derived()" declaration (compiled in .NET) :
==========================================
1>.\Test.cpp(46) : error C2248: 'Base::~Base' : cannot
access private member declared in class 'Base'
1>        .\Test.cpp(35) : see declaration of 'Base::~Base'
1>        .\Test.cpp(32) : see declaration of 'Base'
======================================

If you still in doubt - try this piece of code for yourself.
If you comment out declaration of class Derived, code
compiles just fine.

Now a bit of personal advise for Mms Zubeir : in the future,
before calling other's people opinion a "junk", try to give
it a little thought...and by extension, benefit of doubt to
your own self-assured opinion. This attitude may look good
on interview for some junior/mid-level position - for some
dumb hiring manager, grown on Scott Meyers/C++ in 21 day
type of books :-) But, it will not earn you much respect
amongst professionals. Arrogance is usually sure sign of
ignorance and lack of confidence...never convincing, and
rather good cause for laughter instead. Please remember that
next time before opening your mouth in attempt to discredit
other people's views.
 
0
Boriska
 
 
Answer
CORRECTION to my previous post : please strike out "unless
you define similar  create/destroy methods for class Derived
within Base class scope". Does not change the major idea,
just implications - but not well thought over. 

The correct way is to declare class Derived as a friend to
class Base - like :
class Base
{
friend class Derived;
...
}

then Derived will be able to access Base's private
destructor. But you don't want to let that happen - as I
said - if you want to prohibit any further derivation. But
if you want to make an exception for some predefined types
derived from Base, that is the way.
Cheers and apologies.
 
0
Boriska
 
 
Answer
Thanks for your detailed answer. It's good to see you have 
achieved the purpose partially by using static methods. 
Still, we cannot create objects on the stack rather it 
allows to create objects only on the heap. This is because, 
we have to call the destructor using delete. You have 
provided static methods to do that.

The compiler will not allow to create stack objects since 
it cannot be able to invoke the destructor when unwinding 
stack.

I do not have an idea how to fulfill this requirement.
Anyway, you have rolled out the solution to some extent. 
Thanks.
 
0
Mms Zubeir
 
 
Answer
Mms,
- hmmmm, I am not sure I understand why do you think static
factory methods have anything to do with prohibitng
derivation. Please note, that compiler produces error *at
derived class declaration* and it will still produce the
same error even if you commnet out calls to static
creational methods form main(). 

If I am not mistaken, you are confusing here two completely
unrelated aspects - outer caller's convenience when
instantiating base class and possibility of deriving objects
from it. Static nature of creational methods is merely a
quick and well known way to provide creation/cleanup calls
within the scope of base class - a quick hack, if you will. 

It is perfectly possible to deal completely without
class-level static calls and achieve the same purpose -
prohibiting derivation. You may create instances of base
class form another stack-allocated  object variable - e.g.
from smart pointer-type handle, placed at the stack in
caller's code (which is by the way, quite useful paradigm as
far as C/C++ memory management is concerned). 

E.g., you can use auto_ptr from STL (which is poor choice)
or, better, shared_ptr from BOOST, or develop your own
ref-counted pointer - as I did here, just for the sake of
example.

Here is a quick sample code (again just a way to illustrate
the idea). In the code, Master maintains ownership of object
and implements refcounting, HandlePtr is a stack variable to
provide access to object. Again, I typed it just to
illustrate concept above - just a prototype, not for
detailed discussion. Memory management is a separate topic
from prohibiting derivation.

=======================================================
template <class T> class Master
{
private:
	unsigned _refCnt;
	T*	 _ptr;

	// proihibit copy & assignment
	Master(const Master& rhs) : _refCnt(0), _ptr(NULL) {}
	void operator =(const Master& rhs) {}

public:
	// dflt ctor
	// null0new1 = 0 : _ptr = NULL
	// null0new1 = 1 : _ ptr = new object (assume it has dflt ctor)
	Master(int null0new1=1) : _refCnt(1) { _ptr = null0new1 ?
new T : NULL; } 

	// init ctor : takes ownership of pointee
	Master(T* ptr) : _refCnt(1), _ptr(ptr) {}

	// dtor
	~Master() { delete _ptr; }

	// ref counting
	void grab()		{ ++_refCnt; }
	void release()	{ if (--_refCnt == 0) delete this; }

	T* raw_ptr() { return _ptr;}

	T* checked_ptr()		 
	{ 
		if (_ptr == NULL) throw "Dereferencing NULL pointer";
		return _ptr; 
	}
};

template <class T> class HandlePtr
{
private :
	Master<T>& _master;

public :
	// dflt ctor
	// HandlePtr() - create new object
	// HandlePtr(0) - create NULL ptr
	HandlePtr(int null0new1=1) : _master(*(new
Master<T>(null0new1))) {}

	// init ctor : grabs ownership of pointee
	HandlePtr(T* ptr) : _master(*(new Master<T>(ptr))) {}

	// dtor
	~HandlePtr() { _master.release(); }

	// copy
	HandlePtr(const HandlePtr<T>& rhs) : _master(rhs._master) {
_master.grab(); }

	// assignment
	HandlePtr& operator =(const HandlePtr<T>& rhs)
	{
		if (this != rhs) 
		{
			_master.release(); 
		    _master = rhs._master; 
			_master.grab()
		}
	}

	//member selector and dereference
	T* operator ->() { return _master.checked_ptr(); }		 
	T& operator *()  { return *_master.checked_ptr(); }		 
};


class Base
{
//uncomment below to allow derivation for Derived :
//friend class Derived;

friend class Master<Base>;
private :
	char _id;
	~Base() {};
public :
	Base(char id='0') : _id(id) {};
	char id() { return _id; }
	virtual void print() { cout << "Base : " << id() << endl;}
};

/**
class Derived : public Base
{
friend class Master<Derived>;
public :
	Derived(char id='1') : Base(id) {};
	~Derived() {};
	virtual void print() { cout << "Derived : " << id() << endl;}

};
/**/

int main(int argc, char** argv)
{	
	//HandlePtr<Base> base;
	//base->print();
	/*
	HandlePtr<Derived> derived;
	derived->print();
        */
        return 0;
}
================================================ 

As you can see - no static methods at all. Yet again, you
see the same thing : compiler will produce error at Derived
declaration, even if main() is dummy. So Derived declaration
will not fly. You have to either comment out Derived
declaration or make it a friend to Base - as I described in
previous post.

I don't see why you think the purpose is achieved, as you
said, "partially" :-) Now, if you still feel uncomfortable
about using Base class (from this example) via intermediate
stack-based handle - rather than allocating Base instances
directly on the stack - you probably should think why in the
world does it make such a difference for you. Unless you
have a special affinity for "dot" member selector (which
cannot be overloaded) as opposed to "arrow" member selector,
used by smart pointers - I don't see what's the big freaking
difference between instantiating variables on the stack or
in the heap. Look at Java, look at C# - for exception of
value types in C#, objects are usually allocated on the
heap, and stack variables are mere references. 

And if you still really really want to find solution how to
prohibit further derivation for value types which are
typically allocated on the stack (which seems to be your
major concern) - chances are, your design is really flawed.
Stack-based value types are usually not a good candidates
fro derivation in a good design anyway.

Please, think it over before typing quick reply about
"partial implementation", or "smart pointer semantics" or
whatever else being a limitation and "partial" solution etc.
It could be, actually, quite misleading for beginners :-)

Cheers
 
0
Boriska
 
 
Answer
Mms, thanks for arising my curiosity on the subject - 
actually, there is very elegant solution to make class no
inheritable and allow it on stack. The idea is to virtually
inherit from base class with private destructor. Virtual
inheritance will force derived classes to call virtual base
destructor first, and it would be impossible because its is
private. Much better than solution I described, must admit.
Ok, here is the link with very good description :
http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4143/
 
0
Boriska
 
 
Answer
Thanks for the detailed answer. It's really pleased me the 
way your answer is. Initially I wrote 'partial 
implementation' since I couldn't get the details out of 
your first answer. I am looking at the codeguru solution. 
Thanks once again.
 
0
Mms Zubeir
 
 
Answer
heyy .. very simple yar..
juz add final keyword b4 t class..
u cannot inherit tat class.....
 
0
S.v.vignesh
 
 
Answer
i think we r discussing c++ not java MR S.v.vignesh.....

!!
 
0
Abhishek
 
 
Answer
class A;//forward decleration
class B
{
  B();
public:
  friend A;
}
class A:public virtual B
{
public:
 A()
};
class C:public A
{
public:
  C()
};

int main()
{
  A a; // allowed
  C c;//not allowed
 return 0;
}
 
0
Kamna
 
 
 
Back to Questions Page
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com