1. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    int main(){
        int a= sizeof(signed) +sizeof(unsigned);
        int b=sizeof(const)+sizeof(volatile);
        printf("%d",a+++b);
        return 0;
    }
    Choose all that apply:

    A
    10

    B
    9

    C
    8

    D
    Error: Cannot find size of modifiers

    E
    Error: Undefined operator +++

    Note: Turbo C++ 3.0: 8 Turbo C ++4.5: 8 Linux GCC: 16 Visual C++: 16 Default data type of signed, unsigned, const and volatile is int. In turbo c 3.0 size of int is two byte. So, a = 4 and b =4 Now, a+++b = a++ + b = 4 + 4 //due to post increment operator. =8 Note: In turbo c 4.5 and Linux gcc compiler size of int is 4 byte so your out will be 16
    1. Report
  2. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    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

    Note: 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 compiler 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
    1. Report
  3. Question: What will be output of the following c program?
    #include<stdio.h>
    int main(){
    int goto=5;
    printf("%d",goto);
    return 0;
    }

    A
    5

    B
    10

    C
    20

    D
    Compilation error

    E
    None

    Note: Invalid variable name. goto is keyword in c. variable name cannot be any keyword of c language.
    1. Report
  4. Question: What will be output of the following c program?
    #include<stdio.h>
    int main(){
        int ABC=10;
        printf("%d",abc);
        return 0;
    }

    A
    10

    B
    0

    C
    5

    D
    Compilation error

    E
    None

    Note: Variable name is case sensitive.
    1. Report
  5. Question: What will be output of the following c program?
    #include<stdio.h>
    int main(){
        int printf=12;
        printf("%d",printf);
        return 0;
    }

    A
    12

    B
    0

    C
    5

    D
    Compilation error

    E
    None

    Note: Variable name cannot be pre defined function of included header file.
    1. Report
  6. Question: What will be output of the following c program?
    #include<stdio.h>
    int main(){
        int EOF=12;
        printf("%d",EOF);
        return 0;
    }

    A
    12

    B
    0

    C
    5

    D
    Compilation error

    E
    None

    Note: Variable name cannot be pre defined function of included header file.
    1. Report
  7. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        int a=5,b=10,c=1;
        if(a&&b>c){
             printf("cquestionbank");
        }
        else{
             break;
        }
    }
    Choose all that apply:

    A
    cquestionbank

    B
    It will print nothing

    C
    Run time error

    D
    Compilation error

    E
    None

    Note: Keyword break is not syntactical part of if-else statement. So we cannot use break keyword in if-else statement. This keyword can be use in case of loop or switch case statement. Hence when you will compile above code compiler will show an error message: Misplaced break.
    1. Report
  8. Question: What will be output when you will execute following c code?
    #define PRINT printf("Star Wars");printf(" Psycho");
    #include<stdio.h>
    void main(){
        int x=1;
        if(x--)
             PRINT
        else
             printf("The Shawshank Redemption");
    }
    Choose all that apply:

    A
    Stars Wars Psycho

    B
    The Shawshank Redemption

    C
    Warning: Condition is always true

    D
    Warning: Condition is always false

    E
    Compilation error

    Note: PRINT is macro constant. Macro PRINT will be replaced by its defined statement just before the actual compilation starts. Above code is converted as:
    void main(){
        int x=1;
        if(x--)
             printf("Star Wars");
    printf(" Psycho");
        else
             printf("The Shawshank Redemption");
    }
    If you are not using opening and closing curly bracket in if clause, then you can write only one statement in the if clause. So compiler will think: (i)
    if(x--)
        printf("Star Wars");
    It is if statement without any else. It is ok. (ii)
    printf(" Psycho");
    It is a function call. It is also ok (iii)
    else
             printf("The Shawshank Redemption");
    You cannot write else clause without any if clause. It is cause of compilation error. Hence compiler will show an error message: Misplaced else.
    1. Report
  9. Question: What will be output when you will execute following c code?
    #define True 5==5
    #include<stdio.h>
    void main(){
        if(.001-0.1f)
             printf("David Beckham");
        else if(True)
             printf("Ronaldinho");
        else
            printf("Cristiano Ronaldo");
    }
    Choose all that apply:

    A
    David Beckham

    B
    Ronaldinho

    C
    Cristiano Ronaldo

    D
    Warning: Condition is always true

    E
    Warning: Unreachable code

    Note: As we know in c zero represents false and any non-zero number represents true. So in the above code: (0.001 – 0.1f) is not zero so it represents true. So only if clause will execute and it will print: David Beckham on console. But it is bad programming practice to write constant as a condition in if clause. Hence compiler will show a warning message: Condition is always true Since condition is always true, so else clause will never execute. Program control cannot reach at else part. So compiler will show another warning message: Unreachable code
    1. Report
  10. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        int a=100;
        if(a>10)
             printf("M.S. Dhoni");
        else if(a>20)
             printf("M.E.K Hussey");
        else if(a>30)
               printf("A.B. de villiers");
    }
    Choose all that apply:

    A
    M.S. Dhoni

    B
    A.B. de villiers

    C
    M.S Dhoni M.E.K Hussey A.B. de Villiers

    D
    Compilation error: More than one conditions are true

    E
    None

    Note: In case of if – if else – if else … Statement if first if clause is true the compiler will never check rest of the if else clause and so on.
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd