Monday, January 28, 2019


1. What is the output of this C code?



#include <stdio.h>

    void main()

    {

        int x = 4, y, z;

        y = --x;

        z = x--;

        printf("%d%d%d", x,  y, z);

    }



Ans : 2  3  3







2.What is the output of this C code?





 #include <stdio.h>

    int main()

    {

        switch (printf("Do"))

        {

        case 1:

            printf("First\n");

            break;

        case 2:

            printf("Second\n");

            break;                                                     

        default:

            printf("Default\n");

            break;

        }

    }



/Ans: DoSecond





3.What is the output of this C code?



#include <stdio.h>

    int main()

    {

        int a = 10, b = 10;

        if (a = 5)

        b--;

        printf("%d, %d", a, b--);

    }



Ans: a=5  b=9





4.What is the output of this C code?

#include <stdio.h>

    int main()

    {

        int a = 1, b = 1, c;

        c = a++ + b;

        printf("%d, %d", a, b);

    }




Ans: a=2  b=1







5.#include "stdio.h"

int main()

{

 int _ = 18;

 int __ = 38;

 int ___;

 ___ = _ + __;

 printf ("%i", ___);

 return 0;

}



Answer : 56





6.What will be printed as the result of the operation below:main()

{

 int x = 41, y = 43;

 x = y++ + x++;

 y = ++y + ++x;

 printf ("%d %d", x , y);

}

Answer : 86 130

Description : Its actually compiler dependent. After x = y++ + x++, the value of x becomes 85 and y becomes 44, And y = ++y + ++x will be computed as y = (44) + (86). After computation y becomes 130.





7.What will be printed as the result of the operation main()

{

 int x = 7;

 printf ("%d, %d, %d", x,

    x<<5, x>>5);

}





Answer : 7, 224, 0

Description : As x = 7 so first %d gives 7, second %d will take value of x after left shifting it five times, and shifting is done after converting the values to binary, binary value of 7 (000111) will be left shifted twice to make it binary 224(11100000), so x<<5 is 224 and as left shifting does not effect the original value of x its still 5 so third %d will also show 0.









8.What will be the output?



main()



{

if (1, 0)

 printf ("True");

else

 printf ("False");

}



Answer : False

Description :comma(,) operator returns the value which at the right hand side of , and thus if statement become if(0).







9.what is the output ?



#include<stdio.h>

int main()

{

 char arr[5] = "World is beautiful";

 printf ("%s", arr);

 return 0;

}



Answer : World

A warning is also printed “4:19: warning: initializer-string for array of chars is too long [enabled by default]”

Description : Size of any character array cannot be less than the number of characters in any string which it has assigned. Size of an array can be equal (excluding null character) or greater than but never less than.







10.What is the output of following program?



#include<stdio.h>

void main()

{

 int a = 2;

 switch (a)

 {

  case 4: printf ("A");

  break;

  case 3: printf ("B");

  default : printf("C");

  case 1 : printf ("D");

  break;

  case 5 : printf ("E");

 }

}





Answer : CD

Description : In switch statement default should be at mentioned after all the switch cases. In this case, it gets executed in between and all cases after default are executed before a break statement.





11.What is the output?#include<stdio.h>

#define SQR( x ) ( x * x )

int main()

{

 int b = 5;

 int a = SQR(b+2);

 printf("%d\n", a);

 return 0;

}

Answer : 17









12.#include <stdio.h>



int main()

{

int arr[] = {};

printf("%d", sizeof(arr));

return 0;

}







13.Which one of the following is incorrect?

A. enum fruits = { apple, banana }f;

B. enum fruits{ apple, banana }f ;

C. enum fruits{ apple, banana };

D. enum f{ apple, banana };





14.What will be the output of the C program?



#include<stdio.h>

int main(){

 float me = 5.25;

 double you = 5.25;

 if(me == you)

  printf("I love U");

 else

  printf("I hate U");

 return 0;

}

A. Compilation error



B. I love U

C. Runtime error

D. I hate U



Option: D

Explanation

For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.



15.

DATA MINING

In the University Examinations conducted during the past 5 years, the toppers registration numbers were  7126, 82417914, 7687 and 6657. Your father is an expert in data mining and he could easily infer a pattern in the toppers registration numbers. In all the registration numbers listed here, the sum of the odd digits is equal to the sum of the even digits in the number. He termed the numbers that satisfy this property as Probable Topper Numbers.

Write a program to find whether a given number is a probable topper number or not.




 https://meet.google.com/tcg-zgzv-dye