Structures


  1. What will be the output of the following C code?
    #include <stdio.h>
    struct Result
    {
    int n1;
    char n2;
    struct Result *p;
    };
    int main()
    {
    struct Result Result = {100, 200, &Result};
    printf("%d\n", Result.p->n1);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    100


  1. What will be the output of the following C code?
    #include <stdio.h>
    typedef struct p *q;
    struct p
    {
    int n1;
    char n2;
    q ptr;
    };
    typedef struct p *q;
    int main()
    {
    struct p p = {101, 202, &p};
    printf("%d\n", p.ptr->n1);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    101



  1. Presence of loop in a linked list can be tested by ________.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Comparing the address of nodes by address of every other node


  1. What will be the output of the following C code?
    #include <stdio.h>
    typedef struct p *q;
    int main()
    {
    struct p
    {
    int num1;
    char num2;
    q ptr;
    };
    struct p p = {50, 55, &p};
    printf("%d\n", p.ptr->x);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Compilation Error

    main.c: In function ‘main’:
    main.c:11:29: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
    struct p p = {1, 2, &p};
    ^
    main.c:11:29: note: (near initialization for ‘p.ptr’)
    main.c:12:29: error: dereferencing pointer to incomplete type ‘struct p’
    printf("%d\n", p.ptr->x);
    ^~



  1. What will be the output of the following C code?
     #include <stdio.h>
    int main()
    {
    typedef struct B *ptr;
    struct B
    {
    int num1;
    char num2;
    ptr ptr1;
    };
    struct B b = {15, 25, &b};
    printf("%d\n", b.ptr1->num1);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    15