Wednesday, June 13, 2012

HOW TO FACE AN INTERVIEW

HOW TO FACE AN INTERVIEW

you know to turn off your ringer and dress to impress, but the following surprising slips may not be on your radar.

Don't be cocky
Confidence-i.e., appearing composed and sure of yourself as opposed to like a nervous wreck-is always an appealing quality. Arrogance, on the other hand, made 51 percent of employers want to kick an applicant out of their office on the spot. No matter how much of a superstar you were at your last job, don't make it sound as if you single-handedly pulled off every amazing accomplishment.
Little things like bringing a latte with you, pushing aside a pile of papers on an interviewer's desk so you can plunk down your portfolio, or sneaking a glance at the clock can also make you seem self-important-as if your time and stuff are more valuable than theirs are. Another minor goof they see as arrogant: leaving your sunglasses on top of your head.


Say the magic words
Of course you don't want a potential boss to think you're gunning for the role of office kiss-ass, but playing it too cool can wreck your chances. 55 percent of bosses surveyed said a lack of enthusiasm is one of the biggest mistakes that a candidate make. Seriously.
Get the right message across by using words like 'exciting' and 'interesting'. To show you mean it, read up on the company's history and the industry in general before the interview, and slip some of the things you learned into the conversation.


Don't sound rehearsed
Most of us have gotten this well-meaning advice from a career counsellor: when you're asked "What's your biggest weakness? throw out something that's actually good, like "I'm a workaholic or "I am a perfectionist and won't stop until something's done right . Yeah...whatever! 34 percent of interviewers said they definitely notice when you respond to their questions with tired cliches. Granted, you don't want to confess anything truly incriminating, but it's okay to reveal a real weakness, provided you follow it up with how you're working to correct it.


Don't fail the question test
There are only a few minutes left in the interview, and you get what seems like a throw-away: "Do you have any questions for me? Answering "I don't think so can mess up the awesome impression you just made, since 34 percent of bosses said they're turned off when candidates don't ask smart questions. Why? Doing so shows that you've been paying attention and indicates that you're evaluating them too-not just jumping at the first job opening you hear about.
Prove you're a good listener by requesting that the interviewer elaborate on something she said earlier. And use this all-time great inquiry: "What type of people excel here? It never fails to impress!

Tuesday, June 12, 2012

Question of C Preprocessor with Detailed Solution

Question of c preprocessor with detailed solution

C programming preprocessor questions and explanations
(1) What will be output of following code?

#include
#define max 10

int main(){

    int i;

    i=++max;

    printf("%d",i);

    return 0;
}

(2) What will be output of following code?

#include
#define max 10+2

int main(){

    int i;

    i=max*max;

    printf("%d",i);

    return 0;
}

(3) What will be output of following code?

#include
#define A 4-2

#define B 3-1

int main(){

     int ratio=A/B;

     printf("%d ",ratio);

     return 0;
}

(4) What will be output of following code?

#include
#define MAN(x,y) (x)>(y)?(x):(y)

int main(){

       int i=10,j=9,k=0;

       k=MAN(i++,++j);

       printf("%d %d %d",i,j,k);

       return 0;
}

(5) What will be output of following code?

#include
#define START main() {

#define PRINT printf("*******");

#define END }

START

PRINT

END

(6) What will be output of following code?

#define CUBE(x) (x*x*x)

#define M 5

#define N M+1

#define PRINT printf("RITESH");

int main(){

      int volume =CUBE(3+2);

      printf("%d %d ",volume,N);

      PRINT

      return 0;
}

Solution section 


(1)
output: compiler error.
Explanation:


Here max is preprocessor macro symbol which process first before the actual compilation. First preprocessor replace the symbol to its value in entire the program before the compilation. So in this program max will be replaced by 10 before compilation. Thus program will be converted like this:

int main(){

     int i;

     i=++10;

     printf("%d",i);

     return 0;
}


In this program we are trying to increment a constant symbol.


Meaning of ++10 is:
10=10+1
or 10=11


Which is error because we cannot assign constant value to another constant value .Hence compiler will give error.

(2)


Output: 32
Explanation:


Here max is preprocessor macro symbol which process first before the actual compilation start. Preprocessor replace the symbol to its value in entire the program before the compilation. So in this program max will be replaced by 10+2 before compilation. Thus program will be converted as:
 
int main(){

    int i;

    i=10+2*10+2;

    printf("%d",i);

    return 0;
}


now i=10+2*10+2
i=10+20+2
i=32

(3)


Output: 3
Explanation:

A and B are preprocessor macro symbol which process first before the actual compilation start. Preprocessor replace the symbol to its value in entire the program before the compilation. So in this program A and B will be replaced by 4-2 and 3-1 respectively before compilation. Thus program will be converted as: 

int main(){

    int ratio=4-2/3-1;

    printf("%d ",ratio);

    return 0;
}


Here ratio=4-2/3-1
ratio=4-0-1
ratio=3

(4)


Output: 11 11 11

Explanation:


Preprocessor’s macro which process first before the actual compilation. Thus program will be converted as: 

int main(){

    int i=10,j=9,k=0;

    k=(i++)>(++j)?(i++):(++j);

    printf("%d %d %d",i,j,k);

    return 0;
}


now k=(i++)>(++j)?(i++):(++j);
first it will check the condition
(i++)>(++j)


i++ i.e. when postfix is used with variable in expression then expression is evaluated first with original value then variable is incremented

Or 10>10


This condition is false.
Now i = 10+1 = 11
There is rule, only false part will execute after? i.e. ++j, i++ will be not execute.
So after ++j
j=10+1=11;


And k will assign value of j .so k=11; 

(5)


Output: *******
Explanation:

This program will be converted as: 

main(){

    printf("*******");

}

(6)


Output: 17 6
Explanation: This program will be converted as:

int main(){

    int volume =(3+2*3+2*3+2);

    printf("%d %d ",volume,5+1);

    PRINT

    return 0;
}

If you have any quires or suggestions in above question of c preprocessor with  detailed solution, you can ask here

C Operator Questions with Answers

C Operator Questions with Answers


C programming tricky objective type operators questions and answers with explanation for written test and interview


(1)
What will be output of the following program?
#include
int main(){
    float a=0.7;d 
    if(a<0.7){
         printf("C");
    }
    else{
         printf("C++");
    }
    return 0;
}


Explanation

Output: 

Turbo C++ 3.0: c

Turbo C ++4.5: c

Linux GCC: c

Visual C++: c


Explanation: 
0.7 is double constant (Default). Its binary value is written in 64 bit.

Binary value of 0.7 = (0.1011 0011 0011 0011 0011 0011 0011 0011 0011 0011 0011 )

Now here variable a is a floating point variable while 0.7 is double constant. So variable a will contain only 32 bit value i.e.
a = 0.1011 0011 0011 0011 0011 0011 0011 0011 while
0.7 = 0.1011 0011 0011 0011 0011 0011 0011 0011 0011 0011 0011....
It is obvious a < 0.7


(2)
What will be output of the following program?
        
#include
int main(){
    int i=5,j;
    j=++i+++i+++i;
    printf("%d %d",i,j);
    return 0;
}

Explanation

Output: 

Turbo C++ 3.0: 8 24

Turbo C ++4.5: Compilation error

Linux GCC: Compilation error

Visual C++: Compilation error


Explanation:

Rule :- ++ is pre increment operator so in any arithmetic expression it first increment the value of variable by one in whole expression then starts assigning the final value of variable in the expression.
Compiler will treat this expression j = ++i+++i+++i; as
i = ++i + ++i + ++i;
Initial value of i = 5 due to three pre increment operator final value of i=8.
Now final value of i i.e. 8 will assigned to each variable as shown in the following figure:


So, j=8+8+8
j=24 and
i=8


(3)
What will be output of the following program?
#include
int main(){
    int i=1;
    i=2+2*i++;
    printf("%d",i);
    return 0;
}

Explanation

Output: 

Turbo C++ 3.0: 5

Turbo C ++4.5: 5

Linux GCC: 5

Visual C++: 5


Explanation:
i++ i.e. when postfix increment operator is used any expression the it first assign the its value in the expression the it increments the value of variable by one. So,
i = 2 + 2 * 1
i = 4
Now i will be incremented by one so i = 4 + 1 = 5


(4)
What will be output of the following program?
#include
int main(){
    int a=2,b=7,c=10;
    c=a==b;
    printf("%d",c);
    return 0;
}

Explanation

Output: 

Turbo C++ 3.0: 0

Turbo C ++4.5: 0

Linux GCC: 0

Visual C++: 0


Explanation:
== is relational operator which returns only two values.
0: If a == b is false
1: If a == b is true
Since
a=2
b=7
So, a == b is false hence b=0


(5)
What will be output of the following program?
#include
void main(){
    int x;
    x=10,20,30;
    printf("%d",x);
    return 0;
}

Explanation

Output: 

Turbo C++ 3.0: 10

Turbo C ++4.5: 10

Linux GCC: 10

Visual C++: 10


Explanation :
Precedence table:
Operator
Precedence
Associative
 =
More than ,
Right to left
 ,
Least
Left to right

Since assignment operator (=) has more precedence than comma operator .So = operator will be evaluated first than comma operator. In the following expression
x = 10, 20, 30
First 10 will be assigned to x then comma operator will be evaluated.


(6)
What will be output of the following program?
#include
int main(){
    int a=0,b=10;
    if(a=0){
         printf("true");
    }
    else{
         printf("false");
    }
    return 0;
}

Explanation

Output: 

Turbo C++ 3.0: false

Turbo C ++4.5: false

Linux GCC: false

Visual C++: false


Explanation:
As we know = is assignment operator not relation operator. So, a = 0 means zero will assigned to variable a. In c zero represent false and any non-zero number represents true.
So, if(0) means condition is always false hence else part will execute.


(7)
What will be output of the following program?
#include
int main(){
    int a;
    a=015 + 0x71 +5;
    printf("%d",a);
    return 0;
}

Explanation


Output: 

Turbo C++ 3.0: 131

Turbo C ++4.5: 131

Linux GCC: 131

Visual C++: 131


Explanation:
015 is octal number its decimal equivalent is = 5 * 8 ^ 0 + 1 * 8 ^ 1 = 5 + 8 = 13
0x71 is hexadecimal number (0x is symbol of hexadecimal) its decimal equivalent is = 1 * 16 ^ 0 + 7 * 16 ^ 1 = 1 + 112 = 113
So, a = 13 + 113 + 5 = 131


(8)
What will be output of the following program?
#include
int main(){
    printf("%d %d %d",sizeof(3.14),sizeof(3.14f),sizeof(3.14L));
    return 0;
}

Explanation

Output: 

Turbo C++ 3.0: 8 4 10

Turbo C ++4.5: 8 4 10

Linux GCC: 8 4 12

Visual C++: 8 4 8

Explanation:
3.14f is floating point constant. Its size is 4 byte. 3.14 is double constant (default). Its size is 8 byte. 3.14L is long double constant. Its size is 10 byte. sizeof() operator always return the size of data type which is written inside the(). It is keyword.


(9)
What will be output of the following program?
#include
int main(){
    int x=100,y=20,z=5;
    printf("%d %d %d");
    return 0;
}

Explanation

Output:

Turbo C++ 3.0: 5 20 100

Turbo C ++4.5: 5 20 100

Linux GCC: Garbage values

Visual C++: 5 100 20

By default x, y, z are auto type data which are stored in stack in memory. Stack is LIFO data structure. So in stack first stores 100 then 20 then 5 and program counter will point top stack i.e. 5. Default value of %d in printf is data which is present in stack. So output is revere order of declaration. So output will be 5 20 100.


(10)
What will be output of the following program?
#include        
int main(){
    int a=2;
    a=a++ + ~++a;
    printf("%d",a);
    return 0;
}

Explanation

Output: 

Turbo C++ 3.0: -1

Turbo C ++4.5: 0

Linux GCC: 0

Visual C++: 0


Explanation:
Same theory as question (2) and (13).


(11)
What will be output of the following program?
#include
int main(){
    int a;
    a=sizeof(!5.6);
    printf("%d",a);
    return 0;
}

Explanation

Output:
Turbo C++ 3.0: 2
Turbo C ++4.5: 2
Linux GCC: 4
Visual C++: 4

Explanation:
! is negation operator it return either integer 0 or 1.
! Any operand = 0 if operand is non zero.
! Any operand = 1 if operand is zero.
So, !5.6 = 0
Since 0 is integer number and size of integer data type is two byte.


(12)
What will be output of the following program?
#include
int main(){
    float a;
    (int)a= 45;
    printf("%d,a);
    return 0;
}

Explanation

Output:
Turbo C++ 3.0: Compilation error
Turbo C ++4.5: Compilation error
Linux GCC: Compilation error
Visual C++: Compilation error

Explanation:
After performing any operation on operand it always return some constant value.
(int) i.e. type casting operator is not exception for this. (int) a will return one constant value and we cannot assign any constant value to another constant value in c.

(int)a = 45; is equivalent to
3456 = 45 ( Here 3456 in any garbage value of int(a)).


(13)
What will be output of the following program?
#include
int main(){
     int i=5;
     int a=++i + ++i + ++i;
     printf("%d",a);
     return 0;
}

Explanation

Output: 

Turbo C++ 3.0: 21

Turbo C ++4.5: 21

Linux GCC: 22

Visual C++: 24


Explanation:
Rule : ++ (in ++i) is pre increment operator so in any arithmetic expression it first increment the value of variable by one in whole equation up to break point then start assigning the value of variable in the equation. There are many break point operators in. For example:

(1) Declaration statement.
(2) && or operator.
(3) Comma (,) operator etc.

In the following expression:
int a=++i + ++i + ++i;

Here break point is due to declaration .It break after each increment i.e. (initial value of i=5) after first increment value 6 assign to variable i then in next increment will occur and so on.
So, a = 6 + 7 + 8;


If you have any queries or suggestions in above C operator question with answers, please suggest us.