Showing posts with label C questions. Show all posts
Showing posts with label C questions. Show all posts

Wednesday, 8 November 2017

Operators Questions in C2


6.

Find the output of the following program.

#include void main() 

int y=10;
 if(y++>9 && y++!=10 && y++>11) 
printf("%d", y); 
else 
printf("%d", y); 
}

A. 11
B. 12
C. 13
D. 14
E. Compilation error

Answer: C

---------------------------------------------------------------------------------------------------

7.

Determine output of the following program code.

#include 
void main()
 {
 int a, b=7; a = b<4 :="" b="">4 ? 7>>1 : a; 
printf("%d %d", a, b); 
}

A. 3 7
B. 7 3
C. 8 3
D. 3 8
E. None

Answer: D

------------------------------------------------------------------------------------------------
8.

Choose the correct output for the following program.


#include 
void main() 
{
 int a=10, b=11, c=13, d; 
d = (a=c, b+=a, c=a+b+c); 
printf("%d %d %d %d", d, a, b, c); 
}


A. 50, 13, 11, 13
B. 50, 13, 24, 50
C. 13, 10, 24, 50
D. 50, 13, 24, 13
E. 13, 13, 24, 13


Answer : B


------------------------------------------------------------------------------------------------

9. 

What will be output of the following program?

#include
int main(){
    int a;
    a=015 + 0x71 +5;
    printf("%d",a);
    return 0;
}


Output: 

Turbo C++ 3.0: 131


Turbo C ++4.5: 131


Linux GCC: 131


Visual C++: 131

---------------------------------------------

10.

What is the output of this C code?

int main() 
{
 int i = -5; 
int k = i %4; 
printf("%d\n", k); 
}

A. Compile time error
B. -1
C.  1
D. None

Answer: B

----------------------------------------------------------------
First                  Previous  Next                     Last
----------------------------------------------------------------

More Imp Topics










Operators Questions in C1



An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators −
  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Misc Operators
--------------------------------------------------------------

1. 
Which of the following operator takes only integer operands?

A. +
B. *
C. /
D. %
E. None of these

Answer: D

--------------------------------------------------------

2.
In an expression involving || operator, evaluation 

I. Will be stopped if one of its components evaluates to false 
II. Will be stopped if one of its components evaluates to true
III. Takes place from right to left
IV. Takes place from left to right

A. I and III
B. I and II
C. II and III
D. II and IV
E. III and IV

Answer: D
------------------------------------------------------------

3. 

Which operator from the following has the lowest priority?

A. Assignment operator
B. Division operator
C. Comma operator
D. Conditional operator
E. Unary-operator

Answer: C
------------------------------------------------------------

4. 

What will be the output when following code is executed?

void main() 
{ int a=10, b; 
b = a++ + ++a; 
printf("%d %d %d %d", b, a++, a, ++a);
}

A. 12 10 11 13
B. 22 12 12 13
C. 22 11 11 11
D. 22 14 12 13
E. 22 13 13 13

Answer: E
-------------------------------------------------------------

5.

Identify the correct output of the following code:

void main() 
int w=10, x=5, y=3, z=3; 
if( (w < x ) && (y=z++) ) 
printf("%d %d %d %d", w, x, y, z); 
else 
printf("%d %d %d %d", w, x, y, z); 
}

A. 10 5 4 4
B. 10 5 3 3
C. 10 5 4 3
D. 10 5 3 4
E. 10 5 5 5

Answer: B
----------------------------------------------------------------
First                      Next                               Last
----------------------------------------------------------------

More Imp Topics






















Tuesday, 7 November 2017

Data Types Questions In C3


11. 

What is the output of this C code (on a 32-bit machine) ?

int main() 
{
 int x = 10000; 
double y = 56; 
int *p = &x; 
double *q = &y; 
printf("p and q are %d and %d", sizeof(p), sizeof(q));
 return 0; 
}

A. p and q are 4 and 4
B. p and q are 4 and 8
C. Compiler error
D. p and q are 2 and 8


Answer: A

Explanation:

Size of any type of pointer is 4 on a 32-bit machine. 

Output:
$ cc pgm6.c 
$ a.out 
p and q are 4 and 4

---------------------------------------------------------------------------------------------

12.

Which is correct with respect to size of the datatypes?

A. char > int > float
B. int > char > float
C. char < int < double
D. double > char > int

Answer: C

Explanation:

char has lesser bytes than int and int has lesser bytes than double in any system.

-------------------------------------------------------------------------------------------

13.

Which of the datatypes have size that is variable?

A. int
B. struct
C. float
D. double

Answer: B

Explanation:

Since the size of the structure depends on its fields, it has a variable size.

---------------------------------------------------------------------------------------------

14.

Predict the output

#include
int main()
{
float c = 5.0;
printf ("Temperature in Fahrenheit is %.2f", (9/5)*c + 32); 
return 0; 
}

A. Temperature in Fahrenheit is 41.00
B. Temperature in Fahrenheit is 37.00
C. Temperature in Fahrenheit is 0.00
D. Compiler Error

Answer: B

----------------------------------------------------------------------------------------

First                                                     Previous                      

---------------------------------------------------------------------------------------



More Imp Topics:






















    Data Types Questions In C2


    6. 

    What will be output when you will execute following c code?

    #include
    enum A{
        x,y=5,
        enum B{
             p=10,q
        }varp;
    }varx;

    int main(){
        printf("%d %d",x,varp.q);
        return 0;
    }


    Choose all that apply:


     A.0 11
     B.5 10 
     C.4 11
     D.0 10
     E.Compilation error

    Answer. E

    Explanation:

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

    Nesting of enum constant is not possible in c.

    -------------------------------------------------------------------

    7.

    What will be output when you will execute following c code?

    #include
    int main(){
        char a=250;
        int expr;
        expr= a+ !a + ~a + ++a;
        printf("%d",expr);
        return 0;
    }

    Choose all that apply:

     A.249
     B.250
     C.0
     D.-6
     E.Compilation error

    Answer: D

    Explanation:

    Turbo C++ 3.0: -6
    Turbo C ++4.5: -6
    Linux GCC: -6
    Visual C++: -6

    char a = 250;
    250 is beyond the range of signed char. Its corresponding cyclic value is: -6
    So, a = -6
    Consider on the expression:
    expr= a+ !a + ~a + ++a;
    Operator! , ~ and ++ have equal precedence. And it associative is right to left.
    So, First ++ operator will perform the operation. So value a will -5
    Now,
    Expr = -5 + !-5 + ~-5 + -5
    = -5 + !-5 + 4 - 5
    = -5 + 0 + 4 -5
    = -6

    ---------------------------------------------------

    8.

    What is the range of signed int data type in that compiler in which size of int is two byte?

     A. -255 to 255
     B. -32767 to 32767
     C. -32768 to 32768
     D. -32767 to 32768
     E. -32768 to 32767

    Answer: E

    Explanation:

    Size of int is always equal to word length of micro preprocessor in which your compiler has based.

    ----------------------------------------------------

    9.


    Which of the following is integral data type?



     A.void
     B.char
     C.float
     D.double
     E.None of these

    Answer: B



    Explanation:

    In c char is integral data type. It stores the ASCII value of any character constant.

    -------------------------------------------------------------------


    10.


    What will be output when you will execute following c code?



    #include

    int main(){

        signed x,a;

        unsigned y,b;

        a=(signed)10u;
        b=(unsigned)-10;
        y = (signed)10u + (unsigned)-10;
        x = y;
        printf("%d  %u\t",a,b);
        if(x==y)
             printf("%d %d",x,y);
        else if(x!=y)
             printf("%u  %u",x,y);
        return 0;
    }

    Choose all that apply:
     A.10 -10   0 0
     B.10 -10   65516 -10 
     C.10 -10   10 -10
     D. 10 65526      0 0
     E.Compilation error

    Answer: D

    Explanation:

    Turbo C++ 3.0: 10 65526 0 0
    Turbo C ++4.5: 10 65526 0 0
    Linux GCC: 10 4294967286 0 0
    Visual C++: 10 4294967286 0 0
    
    
    a=(signed)10u;
    signed value of 10u is +10
    so, a=10
     b=(unsigned)-10;
    unsigned value of -10 is :
    MAX_VALUE_OF_UNSIGNED_INT – 10 + 1
    In turbo c 3.0 complier max value of unsigned int is 65535
    So, b = 65526
    y = (signed)10u + (unsigned)-10;
      = 10 + 65526 = 65536 = 0 (Since 65536 is beyond the range of unsigned int. zero is its corresponding cyclic vlaue)
    X = y = 0

    ----------------------------------------------

    First          Previous  Next            Last

    ----------------------------------------------


    More Imp Topics:







    Data Type Questions In C1


    Defination: Data types in c refer to an extensive system used for declaring variables or functions of different types. 
    The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.

    -----------------------------------------------------------------------------------------
    Technical and Interview asked questions for placement in c programming language

    -----------------------------------------------------------------------------------------


    1.


    Consider on following declaration in c:

    (i) short const register i=10;
    (ii) static volatile const int i=10;
    (iii) signed extern float i=10.0;
    (iv) unsigned auto long register i=10;

    Choose correct one:
     A.Only (iv)is correct
     B.Only (ii) and (iv) is correct
     C.Only (i) and (ii) is correct
     D.Only (iii) correct
     E.All are correct declaration

    Answer: C

    -----------------------------------------------------------------------------------------


    2.

    Which of the following is a User-defined data type?

      A. typedef int Boolean;

      B. typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;

      C. struct {char name[10], int age};

      D. All of the mentioned


      Answer: D

      Explanation:

      typedef and struct are used to define user-defined data types.

      -----------------------------------------------------------------------------------------



      3.

      Comment on the output of this C code?

       int main()
       { int a[5] = {1, 2, 3, 4, 5}; 
      int i; 
      for (i = 0; i < 5; i++) 
      if ((char)a[i] == '5')
       printf("%d\n", a[i]);
       else 
      printf("FAIL\n"); 
      }


      A. The compiler will flag an error
      B. Program will compile and print the output 5
      C. Program will compile and print the ASCII value of 5
      D. Program will compile and print FAIL for 5 times

      Answer: D

      Explanation:

      The ASCII value of 5 is 53,
       the char type-casted integral value 5 is 5 only. 


      Output: $ cc pgm1.c 
      $ a.out 
      FAILED 
      FAILED 
      FAILED
      FAILED
      FAILED

      -----------------------------------------------------------------------------------------


      4. 

      Which of the following is a User-defined data type?


      A. typedef int Boolean;

      B. typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;

      C. struct {char name[10], int age};

      D. All of the mentioned

      Answer: D


      Explanation:

      typedef and struct are used to define user-defined data types.


      -----------------------------------------------------------------------------------------


      5.

      What is the size of an int data type?


      A. 4 Bytes

      B. 8 Bytes

      C. Depends on the system/compiler

      D. Cannot be determined.

      Answer: C

      Explanation:

      The size of the data types depend on the system.


      -----------------------------------------------------------------------------------------


       First                         Previous       Next                                             Last

      -----------------------------------------------------------------------------------------


      More Imp Topics

























      100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

      Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...