Typedef


  1. Which of the given option is the correct method for initialization?
    typedef char *string;











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    *string p = ‘A’;


  1. Which option should be selected to work the following C expression?
    string s = "WELCOME";











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    typedef char *string;



  1. Which is the correct syntax to use typedef for struct?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Option A, B and C is correct syntax to use typedef for struct.


  1. What will be the output of the following C code?
    #include <stdio.h>
    typedef struct MM
    {
    int n1, n2;
    }mm;
    int main()
    {
    struct MM m = {22, 44};
    mm k = m;
    printf("%d\n", k.n1);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    22



  1. What will be the output of the following C code?
    #include <stdio.h>
    typedef struct NN
    {
    int n, m;
    }s = {11, 22};
    int main()
    {
    NN nn = s;
    printf("%d\n", nn.n);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    Compilation Error

    main.c:5:5: error: typedef ‘s’ is initialized (use __typeof__ instead)
    }s = {11, 22};
    ^
    main.c: In function ‘main’:
    main.c:8:9: error: unknown type name ‘NN’; use ‘struct’ keyword to refer to the type
    NN nn = s;
    ^~
    struct
    main.c:8:17: error: expected expression before ‘s’
    NN nn = s;
    ^
    main.c:9:26: error: request for member ‘n’ in something not a structure or union
    printf("%d\n", nn.n);