INTERVIEW AND C LANGUAGE

INTERVIEW AND C LANGUAGE
·         -17/5 = -3                                              *   -17%5 = -2
·          17/-5 =-3                                              *   17%-5 = 2
·         -17/-5 = 3                                              *  -17%-5 = -2


1.           x=(a==b);
2.               c=a>b;
3.              d=a<b;
4.              e=(4!=3);
5.              f=(8>=17);
6.              g=(123<=123);

If the given condition( expression i.e. (a>b) ) is true it will store value 1 and if condition is falsethen it will store 0 in the respective variable( i.e. x,c,d,e,f,g).
  •   Conditional operator( ?: ) in C language


Conditional operator work just like if else statments
Example:
(Statement1)? (statement2):(statement3);
If statement1 is true then  statement2 will execute and if statment1 is false then statement3 will execute.

int a=10, b=20, c=30,d;
d=(a<b)?50:100;
printf(“ d = %d”, d);
Output:
d = 50
  •       Nesting of conditional statements


Syntax:
(Statment1) ? (statment2) : (statment3) ? (statment4) : (statment5)? (..............


  •         Use of && operator

res=(a>=10 && b==20);

If both the condition on either side of && is true it will return 1 otherwise it will                                                            return 0.
  •       Use of || operator

                                    res=(a>100 || b<0);

If any of the condition on either side of || is true then it will return 1 otherwise 0.

  •          ‘ ! ‘ is called Not or Negation operator. It is unary operator.

res = !a;

If operand’s value is non-zero it is converted into false value that is 0 and vice    versa.  

  •            x=10;                                                     x=10;

     y=x++                                                    y=++x;

              Output                                                 output
              X = 11                                                  x = 11
              Y = 10                                                  y = 11
  •               printf( “ %d%d%d”, --x, ++x, x++);


Output of the above statment will be determined from right of printf statment.

Comments

Popular posts from this blog

Screen Saver Development In C language

Installing MySQL(5.7) on MacOS (Monterey)