Constants


  1. What will be the output of the following C code?
    #include <stdio.h>
    #define MAX 3
    enum car {AstonMartin = MAX + 1, Audi = AstonMartin + MAX};
    int main()
    {
    enum car c = Audi;
    printf("%d\n", c);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    MAX value is 3 and hence Audi will have value 4 + 3.


  1. What will be the output of the following C code?
     #include <stdio.h>
    int main()
    {
    int n = 020;
    printf("%d", n);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    020 is octal representation of 16.



  1. What will be the output of the following C function?
    #include <stdio.h>
    enum car {AstonMartin, Audi, Chevrolet, Ferrari};
    enum color {Yellow = 5, Green, RedBlue, Blue};
    int main()
    {
    enum car c = Yellow;
    int i;
    i = c;
    printf("%d\n", i);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    c is an integer constant, hence it is compatible.


  1. What will be the output of the following C code?
    #include <stdio.h>
    #define num 12
    int main()
    {
    const int num = 10;
    printf("num = %d\n", num);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    The #define substitutes a with 12 without leaving any identifier, which results in Compilation error.



  1. What will be the output of the following C code?












  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    s is null terminated, but array is not null terminated.