1. 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;
    }

    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
  2. 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");
    }

    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
  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;
    }

    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: Think yourself.
    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);
    }

    A
    The Godfather

    B
    1

    C
    0

    D
    Compilation error

    E
    None of the above

    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: Consider on following declaring of enum. (i) enum cricket {Gambhir,Smith,Sehwag}c; (ii) enum cricket {Gambhir,Smith,Sehwag}; (iii) enum {Gambhir,Smith=-5,Sehwag}c; (iv) enum c {Gambhir,Smith,Sehwag}; Choose correct one:

    A
    Only (i) is correct declaration

    B
    Only (i) and (ii) is correct declaration

    C
    Only (i) and (iii) are correct declaration

    D
    Only (i),(ii) and are correct declaration

    E
    All four are correct declaration

    Note: Syntax of enum data type is: enum [<tag_name>]{ <enum_constanat_name> [=<integer_ value>], … } [<var_name>,…] Note: [] : Represents optional . <>: Represents any valid c identifier
    1. Report
  6. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    int main(){
        signed x;
        unsigned y;
        x = 10 +- 10u + 10u +- 10;
        y = x;
        if(x==y)
             printf("%d %d",x,y);
        else if(x!=y)
             printf("%u  %u",x,y);
        return 0;
    }
    Choose all that apply:

    A
    0 0

    B
    65536 -10

    C
    0 65536

    D
    65536 0

    E
    Compilation error

    Note: Turbo C++ 3.0: 0 0 Turbo C ++4.5: 0 0 Linux GCC: 0 0 Visual C++: 0 0 Consider on the expression: x = 10 +- 10u + 10u +- 10; 10: It is signed integer constant. 10u: It is unsigned integer constant. X: It is signed integer variable. In any binary operation of dissimilar data type for example: a + b Lower data type operand always automatically type casted into the operand of higher data type before performing the operation and result will be higher data type. As we know operators enjoy higher precedence than binary operators. So our expression is: x = 10 + (-10u) + 10u + (-10); = 10 + -10 + 10 + (-10); = 0 Note: Signed is higher data type than unsigned int. So, Corresponding signed value of unsigned 10u is +10
    1. Report
  7. Question: Which of the following is not modifier of data type in c?

    A
    extern

    B
    interrupt

    C
    huge

    D
    register

    E
    All of these are modifiers of data type

    Note: Not available
    1. Report
  8. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    int main(){
        double num=5.2;
        int  var=5;
        printf("%d\t",sizeof(!num));
        printf("%d\t",sizeof(var=15/2));
        printf("%d",var);
        return 0;
    }
    Choose all that apply:

    A
    4 2 7

    B
    4 4 5

    C
    2 2 5

    D
    2 4 7

    E
    8 2 7

    Note: Turbo C++ 3.0: 2 2 5 Turbo C ++4.5: 2 2 5 Linux GCC: 4 4 5 Visual C++: 4 4 5 sizeof(Expr) operator always returns the an integer value which represents the size of the final value of the expression expr. Consider on the following expression: !num =!5.2 =0 0 is int type integer constant and it size is 2 by in TURBO C 3.0 compiler and 4 in the TURBO C 4.5 and Linux GCC compilers. Consider on the following expression: var = 15/2 => var = 7 => 7 7 is int type integer constant. Any expression which is evaluated inside the sizeof operator its scope always will be within the sizeof operator. So value of variable var will remain 5 in the printf statement.
    1. Report
  9. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    int main(){
        const int *p;
        int a=10;
        p=&a;
        printf("%d",*p);
        return 0;
    }
    Choose all that apply:

    A
    0

    B
    10

    C
    Garbage value

    D
    Any memory address

    E
    Error: Cannot modify const object

    Note: Turbo C++ 3.0: 10 Turbo C ++4.5: 10 Linux GCC: 10 Visual C++: 10 In the following declaration const int *p; p can keep address of constant integer.
    1. Report
  10. Question: Consider on following declaration: (i) short i=10; (ii) static i=10; (iii) unsigned i=10; (iv) const i=10; Choose correct one:

    A
    Only (iv) is incorrect

    B
    Only (ii) and (iv) are incorrect

    C
    Only (ii),(iii) and (iv) are correct

    D
    Only (iii) is correct

    E
    All are correct declaration

    Note: Not available
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd