Wednesday, 25 February 2015


Call by value vs Call by reference

 

Call by value

In call by value mechanism, the called function creates a new set of variables in stack and copies the values of the arguments into them. In this case, changes made to the parameter inside the function have no effect on the argument.Consider the function swap() definition as follows.
// function definition to swap the values.
void swap(int x, int y)
{
   int temp;

   temp = x; /* save the value of x */
   x = y;    /* put y into x */
   y = temp; /* put x into y */
  
   return;
}
 Now, let us call the function swap() by passing actual values as in the following example:
#include <iostream>
using namespace std;
 
// function declaration
void swap(int x, int y);
 
int main ()
{
   // local variable declaration:
   int a = 100;
   int b = 200;
 
   cout << "Before swap, value of a :" << a << endl;
   cout << "Before swap, value of b :" << b << endl;
 
   // calling a function to swap the values.
   swap(a, b);
 
   cout << "After swap, value of a :" << a << endl;
   cout << "After swap, value of b :" << b << endl;
 
   return 0;
}

Output will be:-
Before swap, value of a :100
Before swap, value of b :200
After swap, value of a :100
After swap, value of b :200

This happens because when function swap() is invoked, the values of a and b gets copied onto x and y. The function actually swaps x and y while the values of the original variables a and b remain intact.

 

Call by reference

In call by reference mechanism, instead of passing values to the function being called, references/pointers to the original variables are passed.Consider the function swap() definition as follows.
// function definition to swap the values.
void swap(int &x, int &y)
{
   int temp;

   temp = x; /* save the value of x */
   x = y;    /* put y into x */
   y = temp; /* put x into y */
  
   return;
}
 Now, let us call the function swap() by passing actual values as in the following example:
#include <iostream>
using namespace std;
 
// function declaration
void swap(int &x, int &y);
 
int main ()
{
   // local variable declaration:
   int a = 100;
   int b = 200;
 
   cout << "Before swap, value of a :" << a << endl;
   cout << "Before swap, value of b :" << b << endl;
 
   // calling a function to swap the values.
   swap(a, b);
 
   cout << "After swap, value of a :" << a << endl;
   cout << "After swap, value of b :" << b << endl;
 
   return 0;
}

Output will be:-
Before swap, value of a :100
Before swap, value of b :200
After swap, value of a :200
After swap, value of b :100

This happens because when function swap() is invoked, it creates a reference for the first incoming integer a in x and the second incoming integer b in y. Hence the values of the original variables are swapped.


Define sizeof and typedef operators

 

sizeof operator in C++

sizeOf is also an operator not a function, it is used to get information about the amount of memory allocated for data types & Objects. It can be used to get size of user defined data types too.
sizeOf operator can be used with and without parentheses. If you apply it to a variable you can use it without parentheses.

Example
#include <iostream>
using namespace std;
 
int main()
{
   cout << "Size of char : " << sizeof(char) << endl;
   cout << "Size of int : " << sizeof(int) << endl;
   cout << "Size of short int : " << sizeof(short int) << endl;
   cout << "Size of long int : " << sizeof(long int) << endl;
   cout << "Size of float : " << sizeof(float) << endl;
   cout << "Size of double : " << sizeof(double) << endl;
   return 0;
}
Output:- 
Size of char : 1
Size of int : 4
Size of short int : 2
Size of long int : 4
Size of float : 4
Size of double : 8

 

typedef Operator

typedef is a keyword used in C language to assign alternative names to existing types. Its mostly used with user defined data types, when names of data types get slightly complicated. Following is the general syntax for using typedef, 
typedef existing_name alias_name

Lets take an example and see how typedef actually works. 
typedef unsigned long ulong;

The above statement define a term ulong for an unsigned long type. Now this ulong identifier can be used to define unsigned long type variables. 
ulong i, j ;


typedef and Pointers

typedef can be used to give an alias name to pointers also. Here we have a case in which use of typedef is beneficial during pointer declaration.
In Pointers * binds to the right and not the left.
int* x, y ;

By this declaration statement, we are actually declaring x as a pointer of type int, whereas y will be declared as a plain integer.
typedef int* IntPtr ; 
IntPtr x, y, z; 

But if we use typedef like in above example, we can declare any number of pointers in a single statement.

Tuesday, 24 February 2015


What is polymorphism?
 
In programming languages, polymorphism means that some code or operations or objects behave differently in different contexts.Or
 Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.

For example, the + (plus) operator in C++:
4 + 5       <-- integer addition
3.14 + 2.0  <-- floating point addition
s1 + "bar"  <-- string concatenation!
In C++, that type of polymorphism is called overloading.

Types of Polymorphism:
C++ provides two different types of polymorphism.
  • run-time
  • compile-time
run-time:
The appropriate member function could be selected while the programming is running. This is known as run-time polymorphism. The run-time polymorphism is implemented with inheritance and virtual functions.
  • Virtual functions
Virtual functions
            A function qualified by the virtual keyword. When a virtual function is called via a pointer, the class of the object pointed to determines which function definition will be used. Virtual functions implement polymorphism, whereby objects belonging to different classes can respond to the same message in different ways.
What we do want is the selection of the function to be called at any given point in the program to be based on the kind of object for which it is called. This sort of operation is referred to as dynamic linkage, or late binding.

Consider the following simple program which is an example of runtime polymorphism.
#include<iostream>
using namespace std;
  
class Base
{
public:
    virtual void show() { cout<<" In Base \n"; }
};
  
class Derived: public Base
{
public:
    void show() { cout<<"In Derived \n"; }
};
  
int main(void)
{
    Base *bp = new Derived;
    bp->show();  // RUN-TIME POLYMORPHISM
    return 0;
}
Output:
In Derived
Note:- virtual functions are resolved late, at runtime and without virtual keyword the output will be In Base. 

compile-time:
The compiler is able to select the appropriate function for a particular call at compile-time itself. This is known as compile-time polymorphism. The compile-time polymorphism is implemented with templates.
  • Function name overloading
  • Operator overloading

Function overloading in C++:

You can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list.
Following is the example where same function print() is being used to print different data types:
 
#include <iostream>
using namespace std;
 
class printData 
{
   public:
      void print(int i) {
        cout << "Printing int: " << i << endl;
      }

      void print(double  f) {
        cout << "Printing float: " << f << endl;
      }

      void print(char* c) {
        cout << "Printing character: " << c << endl;
      }
};

int main(void)
{
   printData pd;
 
   // Call print to print integer
   pd.print(5);
   // Call print to print float
   pd.print(500.263);
   // Call print to print character
   pd.print("Hello C++");
 
   return 0;
}

Operators overloading in C++:

You can redefine or overload most of the built-in operators available in C++. Thus a programmer can use operators with user-defined types as well.

/* Simple example to demonstrate the working of operator overloading*/
#include <iostream>
using namespace std;
class temp
{
   private:
      int count;
   public:
       temp():count(5){  }
       void operator ++() { 
        count=count+1; 
       }
       void Display() { cout<<"Count: "<<count; }
};
int main()
{
    temp t;
    ++t;        /* operator function void operator ++() is called */
    t.Display();
    return 0;
}
Output 
Count: 6 
If the code below was used instead, then the value of count will be decreased by 100 if ++ operates on object.

void operator ++() { 
        count=count-100; 
       }
Following is the list of operators, which can not be overloaded:
::,.*, . and   ?:

Wednesday, 11 February 2015

Some HR interview questions and answers

1. Tell us something about yourself.

This is the first question, you can expect during any interview you face. This usually is a question to start the communication and set the ball rolling for the interview. You can answer this question by providing some information about your work experience, technologies you have worked upon, educational qualifications. If you are a fresh graduate, you can provide some information about your family also.
The trick is to put the full stop at the right place to provoke the next question you want. For e.g. “Recently I developed a website using Drupal. It was quite an interesting but challenging job which I enjoyed.”

2. Why do you consider yourself a suitable candidate for this position?

The answer to this question lies in the preparation you did before the interview. It is extremely important that you research the requirements of the position well and match them with your skills.
For e.g. if the position requires an Asp.net developer with good knowledge of health care domain, tell the interviewer about your technical skills and your domain knowledge.
Fresh graduates can talk about their technical skills, ability to learn and grasp things quickly.

3. Why do you want to leave your present job or company?

You may want to leave your present job for any reason but make sure that you do not talk bad about your manager, company or job. It reflects your complaining attitude.
Provide a sincere reason for e.g. “I think, I have grown up with my last employer as much as I could. I want to grow further and I believe that is possible with a new employer.”

4. You have stayed in your current job for quite a long time, why?

There are many people who do not change their jobs for years and when they go out looking for a new employer, this is one of the most important questions they are asked. Some people might look upon staying with the same employer for long as “lack of ambition”.
A good answer to this question can be something like, “Yes, you are right. I stayed with my last employer for almost 5 years but I was continuously growing in the company, doing new things, handling bigger challenges. So, I was quite happy working with them for these many years.” You can then talk about how you grew with your last employer.

5. What do you know about us?

Research the company and its business a bit before appearing for the interview. Also, find out a bit about the technologies they work upon. You don’t need to know everything inside out but having a fair idea about the company makes you appear interested in the position, to be taken seriously.
For e.g. I see that your company does a lot of projects based on OpenSource platforms like Joomla, Drupal, Magento which is quite interesting as I have a similar kind of experience.

6. What do you do to improve your knowledge?

The field of IT is very revolutionary. It is extremely important to keep yourself abreast with the new technological developments and this needs you to take some time out of your work schedule so that you can keep sharpening your saw.
To answer this question, you can tell the recruiter about the forums which you keep visiting, blogs which you keep reading. It will be an advantage if you are a member of some local user group.

7. Can you perform under pressure?

Most of the times, the job of software development is that of working under pressure. Sometimes, it will be the pressure of delivering on time while it can be that of a bug that has sprung all of a sudden in your code.
So, expect pressure in everything you do. It is important to maintain your performance and develop strategies to deliver under pressure. You can then go ahead an talk about your way of dealing with pressure and performing under it.

8. Tell us some of your strengths.

Again, it is important to study the requirements of the position before you appear for the interview. List out your strengths and offer the ones that this role demands.
For e.g. if you are appearing for the position of a Tech Lead – VB.net, talk about your VB.net skills, any extra knowledge which you have about coding with VB.net in comparison to other candidates, your team management skills etc.

9. Tell us some of your weaknesses.

You have to be careful while answering this question. Do not offer a weakness which will directly affect your selection but at the same time saying that you do not have any weakness will not be right too. Every human being has weaknesses, so it is perfectly OK for you to have some too.
The best way to answer this question will be to turn one of your strengths as a weakness and say that others accuse you of having this weakness but you think it is important to work in this manner. For e.g.: “My colleagues accuse me of paying to much attention to syntaxes but I believe it is important when you are writing the code to avoid spending too much time on finding and fixing the bugs later on.”
Another way to answer this question is to offer a totally un-related weakness for e.g. “I have been staying alone for so many years now but I still can’t cook independently.”

10. Are you comfortable working in a team?

The whole work of software development or IT is a team work. So, the only answer to this question can be: “Yes, I am comfortable working in a team.” If you have any problems in working as a team, it is important to work on them and develop yourself as a team player.

11. How do you rate your communication skills?

Again, IT is about dealing with people within and out of the company. So, it is important to have good communication skills. By good communication skills we mean, ability to understand and explain in a common language. So, if you believe that your communication skills are weaker, you need to work on them.
Anything less than average or good is not acceptable here.

12. You do not have all the experience we need for this position?

It is not possible for a candidate to have all the experience an employer requires. Even if you match yourself up to the expectations on technical front, there will be some difference in the work environment. And, it is absolutely fine.
The best way to deal with this question is to analyse the requirements of the position well and match your skills as close to them as possible. If something is still left untouched, offer your quick grasping power and ability to learn quickly as a solution & back it up with an example from the past.

13. How would you compensate for the lack of experience you have for this position?

As we discussed in the last question, your ability to understand and pick up new things quickly should be able to compensate for the lack of work experience you have.

14. If you were hiring for this position, what qualities would you look for in a potential candidate?

Closely understand the qualities and skills a person holding the position would need and match them with the qualities you have.
If you believe that you are missing a big quality required for the position under discussion, say that, “I understand that this is an important quality required in the person holding this position but given a chance, I will inculcate it in me.” Back it up with a confident body language.

15. Do you know anyone who works for us?

Offer some one’s name if they really know you well and can offer a positive feedback about you.

16. What is your style of management?

In today’s scenario, everything needs customization, so here also, one size can’t fit all i.e. one management style won’t work in all situations. So, offer “situational” as your style of management.

17. Have you ever fired anyone? How would you go about firing a person, if required?

The basic purpose of asking this question is to check your EQ and see if you have the guts to make tough decisions. If you have fired anyone in the past, discuss your experience and approach. If you have never done so in the past, discuss the approach you would take to make and implement such a decision. Keep the focus of your answer on the fact that you would try to do your best to ensure that your team performs to its best but if a particular member is not able to perform even after you taking all the steps to help him, you would make the tough decision to ensure that the project doesn’t suffer.

18. What irritates you about co-workers?

The purpose of this question is to see how well you can fit into a team. Basically, you should not have a problem with a person, although you can have a problem with the style of working.
So, to answer this question you can simply say, “I understand that IT is about team work, so we can’t afford to problems with co-workers but if someone is not serious about their work or does a low quality work affecting the whole project, I definitely do not like it”

19. Is there any particular kind of person you can not work with?

For the reason given in the above questions, the answer to this question should be a “No”. This is basically a different way of putting up the last question.

20. What qualities would you look for in your senior?

You can mention some generic qualities like intelligence, good sense of humour, dedicated to his team etc., which all the managers think that they have in abundance.

21. What motivates you at work?

To answer this question, you can mention things like – new challenges, good environment which all employers think that they offer.

22. Will you be happy to work in night shifts or over the weekends?

You need to answer this question taking into consideration what is suitable for you. Say that you can work in the night shifts, only if you can really do it.

23. Have you ever committed a mistake at work?

To err is human. So, it is perfectly OK if you committed a mistake at work but before answering the question analyse the magnitude of mistake you did and the effect it had on the company.
What is more important is – what did you do to rectify the mistake and make sure that you don’t do it again?
So, mention the mistake you committed and keep the focus of the answer on the steps you took to rectify it.

24. What position would you prefer while working on a project?

This question is for you to answer based on the skills and qualities you have. If you have the capability to handle different positions, discuss that also in the interview.

25. What are the most important things for you as a manager?

The two things which should be most important for a manager to succeed in his role are:
a.) His team should be happy and keep performing
b.) The project he is working on with his team is successfully finished with minimum problems.

26. Will you be happy to re-locate, if required?

Again, a question for you to answer based on your position. If you are anticipating this question in the interview, it is better to discuss this with your family also before you go to face the interview.

27. What kind of a salary are you looking for?

Try to put the ball back in interviewer’s court by asking him about the salary they offer for a position like this. Most of the big companies will have a fixed remuneration for each level.
However, if this is negotiable, you will have more negotiation power if you have some work experience. So, know your lower limit (amount below which you can’t go) and also know the maximum salary in the industry for the position then put forward a figure which is not very exact. It is better to mention a range. For e.g. if you are expecting something around 55 K, say that you expect something in mid fifties. Don’t keep the range to broad otherwise you will be offered something towards the lower end.
If you are a fresher, most of the times you will have to accept the company’s offering for the position. However, if you find it too less, you can definitely discuss that during the interview.

28. Do you have any questions for us?

This is usually the last question you can expect during an interview. It is extremely important to have some intelligent questions to ask the interviewer otherwise you may just sound dull and un-interested. Research the company a bit and discuss if they have been in news recently. You can also discuss about the growth prospects for you within the company etc.

29. Discuss the most stressful situation you came across in your previous job.

Here you should discuss a stressful situation that you were able to overcome and keep a positive tone, do not say you never came across a stressful situation. Typical answers can be:
-Our team’s targets were increased three fold and initially everyone was overwhelmed by the number, but we discussed it with our manager and he was co-operative and understood the situation. But he wanted us to give it a try and was ready to reduce the targets to a more realistic number.
-You can also talk about a very demanding project where you worked for long hours/2 shifts and had to sacrifice on family time, but once the project was done you got recognition for the hard work and you were over the stress.

30. For how long do you expect to stay with our organization?

You should ensure that you give an impression that you will pay back more than what you take from the company:
-You can say I will stay here as far as I see an opportunity for growth, as I am looking for a stability in work place
-If they stress on number of years say 3-4 years, and more if I can explore new challenges/growth opportunities

31. Why should we hire you?

-Here you should discuss the profile you have applied for and your strengths/experience with which you can add value to the job
-Discuss your achievements at your previous job, and say that I have developed my skills to suit my current profile, but I want to develop myself futher and face new challenges, and for that I need to change my job.
- I will always be willing to change roles share responsibilities to suit company requirements

32. Discuss your strengths

Discuss strengths that show your professional expertise, some of the answers could be:
-Multi tasking: Say I have been working on mulitple project and I am required to keep tabs on each project and co-ordinate with a lot of teams, and I am able to do it efficiently.
-Problem Solving: You can say that in my current job role I have spent a good time to know how to solve problems. My team members see me as a go-to person to solve issues.
-Communication
-Team player
-Quick learner
Support each point with your examples

33. Discuss your weaknesses and how do you plan to overcome it

Discuss weaknesses in positive light always discuss how you plan to overcome it, some of the answers could be:
-I am always willing to take up additional responsibilities, but I end up being over worked so now I am realistic about what I can do, so that I do work to the required standards
-If you lack certain technical skill, which is not crucial for the job you can state that and say you are planning to take up a training course/certification to get over it
-If you do not wish to discuss your weakness, you can say, I cannot compete with Rajnikant :P

34. What is your idea of an ideal company?

Do not go over board and ask for , it might give an impression that you are too demanding, some of the answers could be:
-An ideal company provides maximum opportunities for growth of employees.
-They provide comfortable and flexible work environment, so that employees can perform at their best and work towards company’s benefit.
-A company that encourages learning
-A company that encourages open culture

35. Why are you leaving your previous job?

Do not go around defaming your company, it will give a bad impression about you.
Give reasons such as:
-Professional Growth
-New challenges
-Change in profile
-Planning to relocate (if applicable)
-With time I found my job was becoming monotonous and I didn’t want this to have any impact on the job I was doing for my employer
-I am not actively looking for a job change but, I saw this opening and it looked interesting.

36. Tell us something about your achievements at your previous job.

-Talk about your professional acheivements, if you were recognised as a high performer or you got good feedback from your manager
-You can also discuss you annual ratings
-Discuss your promotions/appraisals

37. Tell us what do you know about our company

-Browse through the company website and make sure you know what the company does and make sure you do so in short
-Discuss the positives aspects of the company, the interviewer should feel that you have done your home work
10. Why do you want to work for us?
-Start by discussing the profile you have applied for and go on to say that the organization would provide an opportunity to enhance your knowledge and help you to grow professionally
-Discuss how you would be of use to the organization and how you plan to develop your professional competencies

38. Are you willing to relocate/travel?

-Always say yes if you need the job
-You can ask whether they will compensate for relocation costs

39. Are you a good team player?

Companies look for team players as well as those who are self starters and can work independently, so you need to be versatile:
-You should show that you enjoy working in a team. Say that you are open to suggestions from team members and seniors.
-It is always good to work in a team as one can get the support of other members and in times of crisis everyone can work together to achieve the goal.

40. Can you work independently?

-Yes, I can work independently without supervision or support from a team
Do not emphasize on working independently as that will be seen as an inability to work with others.

41. Do you have any questions for us?

Always have a question ready to answer this one:
-You can ask whether the company allows for lateral and vertical role changes
-You can also ask whether the company encourages learning and development of employees
-Ask whether the company has plans for expansion
-You can also discuss your role in detail

42. Are you willing to work for long hours, if the project demands that from you?

-Discuss situations when you must have done so to fulfill project requirements in the past

43. What is your current CTC and what are your expectations?

-Be honest about your CTC, as you will have to produce you salary slip as a proof of emplyment
-Be realistic when you state your expected CTC, you can ask for a 30-40% hike
-If you are underpaid at your current company you can look for the standard salary paid for the experience you have and ask for that amount

44. Are you planning to go for further studies?

Be transparent in your answer.
-If you are pursuing further studies, say so. Tell them why you want to go for that course
-If you are taking up a distance education course or a part time course, they should know, as you will need to take leaves when you appear for exams

45. Tell us something about yourself, discuss 5 characteristics

List down points that will help you professionally:
-Independent
-Responsible
-Hard working
-Multi tasker
-Prompt
-Add your characteristcs

46. Tell us something about your hobbies

Answer it with honesty, as they can go deeper into this discussion. You can include:
-Browsing the internet
-Blogging,
-Listening to music,
-Chatting with friends
-Reading newspapers,
-Reading books,
-Shopping,
-Watching movies….

Tuesday, 10 February 2015

Top 5 job interview tips

If you're counting down the days till your next job interview, these helpful hints will help you get in the right mood so you can leave a lasting impression on the interviewers...


#1 Do your research
Fail to plan, and you plan to fail. You are certain to be asked specific questions about the company, so make sure you've done your homework on things like their last year's profits and latest product launches. Also take a look at the latest developments in the industry so you can converse with confidence.


#2 Practice your answers

Although there is no set format that every job interview will follow, there are some questions that you can almost guarantee will crop up. You should prepare answers to some of the most common interview questions about your personal strengths and weaknesses, as well as being able to explain why you would be the best person for the job.


#3 Look the part
Appearances shouldn't matter, but the plain fact is that you are often judged before you've even uttered a word. Make sure your shoes are polished, your clothes fit correctly and that your accessories are subtle. Dressing one level above the job you're applying for shows a desire to succeed.


#4 Stay calm
Good preparation is the key to staying in control. Plan your route, allowing extra time for any unexpected delays and get everything you need to take with you ready the night before. Remember to speak clearly, smile and remember that your interviewers are just normal people, and the may be nervous too!


 #5 Ask questions
You should always have some questions for your interviewer to demonstrate your interest in the position. Prepare a minimum of five questions, some which will give you more information about the job and some which delve deeper into the culture and goals of the company.