1. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        int x=-1,y=-1;
        if(++x=++y)
             printf("R.T. Ponting");
        else
             printf("C.H. Gayle");
    }
    Choose all that apply:

    A
    R.T Ponting

    B
    C.H. Gayle

    C
    Warning: x and y are assigned a value that is never used

    D
    Warning: Condition is always true

    E
    Compilation error

    Note: Consider following statement: ++x=++y As we know ++ is pre increment operator in the above statement. This operator increments the value of any integral variable by one and return that value. After performing pre increments above statement will be: 0=0 In C language it is illegal to assign a constant value to another constant. Left side of = operator must be a container i.e. a variable. So compiler will show an error message: Lvalue required In c if you assign any value to variable but you don’t perform any operator or perform operation only using unary operator on the variable the compiler will show a warning message: Variable is assigned a value that is never
    1. Report
  2. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        if(sizeof(void))
             printf("M. Muralilidaran");
        else
             printf("Harbhajan Singh");
    }
    Choose all that apply:

    A
    M. Muralilidaran

    B
    Harbhajan Singh

    C
    Warning: Condition is always false

    D
    Compilation error

    E
    None

    Note: It illegal to find size of void data type using sizeof operator. Because size of void data type is meaning less.
    1. Report
  3. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        int m=5,n=10,q=20;
        if(q/n*m)
             printf("William Gates");
        else
             printf(" Warren Buffet");
             printf(" Carlos Slim Helu");
    }
    Choose all that apply:

    A
    William Gates

    B
    Warren Buffet Carlos Slim Helu

    C
    Run time error

    D
    Compilation error

    E
    None

    Note: Consider the following expression: q / n * m In this expression there are two operators. They are: /: Division operator *: Multiplication operator Precedence and associate of each operator is as follow:
    PrecedenceOperatorAssociate
    1/,*Left to right
    Precedence of both operators is same. Hence associate will decide which operator will execute first. Since Associate is left to right. So / operator will execute then * operator will execute. = q / n * m = 20 / 10 * 5 = 2 * 5 =10 As we know in c zero represents false and any non-zero number represents true. Since 10 is non- zero number so if clause will execute and print: William Gates Since in else clause there is not any opening and closing curly bracket. So compiler will treat only one statement as a else part. Hence last statement i.e. printf(" Carlos Slim Helu"); is not part of if-else statement. So at the end compiler will also print: Carlos Slim Helu So output of above code will be: William Gates Carlos Slim Helu
    1. Report
  4. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        if(!printf("Mukesh Ambani"))
        if(printf(" Lakashmi Mittal"));
    }
    Choose all that apply:

    A
    Mukesh Ambani

    B
    Lakashmi Mittal

    C
    It will print nothing

    D
    Mukesh Ambani Lakashmi Mittal

    E
    Compilation error: if statement without body

    Note: Return type of printf function is int. This function return a integral value which is equal to number of characters a printf function will print on console. First of all printf function will: Mukesh Ambani. Since it is printing 13 character so it will return 13. So, !printf("Mukesh Ambani") = !13 = 0 In c language zero represents false. So if(0) is false so next statement which inside the body of first if statement will not execute.
    1. Report
  5. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        if("ABC") printf("Barack Obama\n");
        if(-1)    printf("Hu Jintao\n");
        if(.92L)  printf("Nicolas Sarkozy\n");
        if(0)     printf("Ben Bernanke\n");
        if('W')   printf("Vladimir Putin\n");
    }
    Choose all that apply:

    A
    It will print nothing

    B
    Barack Obama Hu Jintao Nicolas Sarkozy Vladimir Putin

    C
    Barack Obama Hu Jintao Nicolas Sarkozy Ben Bernanke Vladimir Putin

    D
    Hu Jintao Nicolas Sarkozy Vladimir Putin

    E
    Compilation error

    Note: “ABC”: It is string constant and it will always return a non-zero memory address. 0.92L: It is long double constant. ‘W’: It is character constant and its ASCII value is As we know in c language zero represents false and any non-zero number represents true. In this program condition of first, second, third and fifth if statements are true.
    1. Report
  6. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        if(0xA)
             if(052)
                 if('\xeb')
                     if('\012')
                          printf("Tom hanks");
                     else;
                 else;
             else;
        else;
    }
    Choose all that apply:

    A
    Tom hanks

    B
    Compilation error: Misplaced else

    C
    Compilation error: If without any body

    D
    Compilation error: Undefined symbol

    E
    Warning: Condition is always true

    Note: oxA: It is hexadecimal integer constant. 052: It octal integer constant. ‘\xeb’: It is hexadecimal character constant. ‘\012’: It is octal character constant. As we know in c zero represents false and any non-zero number represents true. All of the above constants return a non-zero value. So all if conditions in the above program are true. In c it is possible to write else clause without any body.
    1. Report
  7. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        int a=10;
        if(printf("%d",a>=10)-10)
             for(;;)
                 break;
        else;
    }
    Choose all that apply:

    A
    It will print nothing

    B
    0

    C
    1

    D
    Compilation error: Misplaced else

    E
    Infinite loop

    Note: Return type of printf function is int. This function return a integral value which is equal to number of charcters printf function will print on console. Operator >= will return 1 if both operands are either equal or first operand is grater than second operand. So a>=10 will return 1 since a is equal to 10.Thus printf function will print 1. Since this function is printing only one character so it will also return 1. So, printf("%d",a>=10) - 10 = 1 - 10 = -9 Since -9 is non-zero number so if(-9) is true condition hence if clause will execute which contains an infinite loop but due to break keyword it will come out of loop.
    1. Report
  8. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        int a=5,b=10;
        if(++a||++b)
             printf("%d  %d",a,b);
        else
             printf("John Terry");
    }
    Choose all that apply:

    A
    5 10

    B
    6 11

    C
    6 10

    D
    5 11

    E
    John Terry

    Note: Consider the following expression: ++a || ++b In this expression || is Logical OR operator. Two important properties of this operator are: Property 1: (Expression1) || (Expression2) || operator returns 0 if and only if both expressions return a zero otherwise it || operator returns 1. Property 2: To optimize the execution time there is rule, Expression2 will only evaluate if and only if Expression1 return zero. In this program initial value of a is 5. So ++a will be 6. Since ++a is returning a non-zero so ++b will not execute and if condition will be true and if clause will be executed.
    1. Report
  9. 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
  10. 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
Copyright © 2024. Powered by Intellect Software Ltd