1. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        if('\0');
        else if(NULL)
             printf("cquestionbank");
        else;
    }
    Choose all that apply:

    A
    cquestionbank

    B
    It will print nothing

    C
    Warning: Condition is always true

    D
    Warning: Unreachable code

    E
    Compilation error: if statement without any body

    Note: ‘\0’ is null character constant. Its ASCII value is zero. if(0) means false so program control will check it else if clause. NULL is macro constant which has been defined in stdio.h which also returns zero.
    1. Report
  2. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        int a=5,b=10;
        clrscr();
        if(a<++a||b<++b)
             printf("%d  %d",a,b);
        else
             printf("John Terry");
    }
    Choose all that apply:

    A
    5 10

    B
    6 11

    C
    6 10

    D
    Compilation error

    E
    John Terry

    Note: Consider the following expression: a<++a||b<++b In the above expression || is logical OR operator. It divides any expression in the sub expressions. In this way we have two sub expressions: (1) a<++a (2) b<++b In the expression: a< ++a There are two operators. There precedence and associate are:
    PrecedenceOperatorAssociate
    1++Right to left
    2<Left to right
    From table it is clear first ++ operator will perform the operation then < operator. One important property of pre-increment (++) operator is: In any expression first pre-increment increments the value of variable then it assigns same final value of the variable to all that variables. So in the expression: a < ++a Initial value of variable a is 5. Step 1: Increment the value of variable a in whole expression. Final value of a is 6. Step 2: Now start assigning value to all a in the expression. After assigning 6 expression will be: 6 < 6 Since condition is false .So second expression i.e. b<++b will be evaluated. Again 11 < 11 is false. So || will operator will return zero and else clause will execute.
    1. Report
  3. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        static int i;
        for(;;)
        if(i+++"The Matrix")
              printf("Memento");
        else
             break;
    }
    Choose all that apply:

    A
    It will print Memento at one time

    B
    It will print Memento at three times

    C
    It will print Memento at ten times

    D
    It will print Memento at infinite times

    E
    Compilation error: Unknown operator +++

    Note: Not available
    1. Report
  4. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        int x=1;
        if(x--)
             printf("The Godfather");
             --x;
        else
             printf("%d",x);
    }
    Choose all that apply:

    A
    The Godfather

    B
    1

    C
    0

    D
    Compilation error

    E
    None

    Note: If you are not using { and } in if clause then you can write only one statement. Otherwise it will cause of compilation error: Misplace else
    1. Report
  5. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        if('\0');
        else if(NULL)
             printf("cquestionbank");
        else;
    }
    Choose all that apply:

    A
    cquestionbank

    B
    It will print nothing

    C
    Warning: Condition is always true

    D
    Warning: Unreachable code

    E
    Compilation error: if statement without any body

    Note: ‘0’ is null character constant. Its ASCII value is zero. if(0) means false so program control will check it else if clause. NULL is macro constant which has been defined in stdio.h which also returns zero.
    1. Report
  6. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        int x=1,y=2;
        if(--x && --y)
             printf("x=%d  y=%d",x,y);
        else
             printf("%d %d",x,y);
    }
    Choose all that apply:

    A
    1 2

    B
    x=1 y=2

    C
    0 2

    D
    x=0 y=1

    E
    0 1

    Note: Consider the following expression: --x && --y In this expression && is Logical AND operator. Two important properties of this operator are: Property 1: (Expression1) && (Expression2) && operator returns 1 if and only if both expressions return a non-zero value other wise it && operator returns 0. Property 2: To optimize the execution time there is rule, Expression2 will only evaluate if and only if Expression1 return a non-zero value. In this program initial value of x is 1. So –x will be zero. Since -–x is returning zero so -–y will not execute and if condition will be false. Hence else part will be executed.
    1. Report
  7. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        signed int a=-1;
        unsigned int b=-1u;
        if(a==b)
             printf("The Lord of the Rings");
        else
             printf("American Beauty");
    }
    Choose all that apply:

    A
    The Lord of the Rings

    B
    American Beauty

    C
    Compilation error: Cannot compare signed number with unsigned number

    D
    Compilation error: Undefined symbol -1u

    E
    Warning: Illegal operation

    Note: Not available
    1. Report
  8. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        char c=256;
        char *ptr="Leon";
        if(c==0)                                
             while(!c)
                 if(*ptr++)
                     printf("%+u",c);
                 else
                     break;
    }
    Choose all that apply:

    A
    +256+256+256+256

    B
    0000

    C
    +0+0+0+0

    D
    It will print +256 at infinite times

    E
    Compilation error

    Note: In the above program c is signed (default) char variable. Range of signed char variable in Turbo c is from -128 to 127. But we are assigning 256 which is beyond the range of variable c. Hence variable c will store corresponding cyclic value according to following diagram: Since 256 is positive number move from zero in clock wise direction. You will get final value of c is zero. if(c==0) It is true since value of c is zero. Negation operator i.e. ! is always return either zero or one according to following rule: !0 = 1 !(Non-zero number) = 0 So, !c = !0 =1 As we know in c zero represents false and any non-zero number represents true. So while(!c) i.e. while(1) is always true. In the above program prt is character pointer. It is pointing to first character of string “Leon” according to following diagram: In the above figure value in circle represents ASCII value of corresponding character. Initially *ptr means ‘L’. So *ptr will return ASCII value of character constant ‘L’ i.e. 76 if(*ptr++) is equivalent to : if(‘L’) is equivalent to: if(76) . It is true so in first iteration it will print +0. Due to ++ operation in second iteration ptr will point to character constant ‘e’ and so on. When ptr will point ‘\0’ i.e. null character .It will return its ASCII value i.e. 0. So if(0) is false. Hence else part will execute.
    1. Report
  9. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        int a=2;
        if(a--,--a,a)
             printf("The Dalai Lama");
        else
             printf("Jim Rogers");
    }
    Choose all that apply:

    A
    The Dalai Lama

    B
    Jim Rogers

    C
    Run time error

    D
    Compilation error: Multiple parameters in if statement

    E
    None

    Note: Consider the following expression: a-- , --a , a In c comma is behaves as separator as well as operator.In the above expression comma is behaving as operator.Comma operator enjoy lest precedence in precedence table and its associatively is left to right. So first of all left most comma operator will perform operation then right most comma will operator in the above expression. After performing a-- : a will be 2 After performing --a : a will be 0 a=0 As we know in c zero represents false and any non-zero number represents true. Hence else part will execute.
    1. Report
  10. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
         int check=2;
         switch(check){
            case 1: printf("D.W.Steyn");
            case 2: printf(" M.G.Johnson");
            case 3: printf(" Mohammad Asif");
            default: printf(" M.Muralidaran");
         }
    }
    Choose all that apply:

    A
    M.G.Johnson

    B
    M.Muralidaran

    C
    M.G.Johnson Mohammad Asif M.Muralidaran

    D
    Compilation error

    E
    None

    Note: If we will not use break keyword in each case the program control will come in each case after the case witch satisfy the switch condition.
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd