C Programming – Arrays of Structures

C Programming - Arrays of Structures


Question 1
The correct syntax to access the member of the ith structure in the array of structures is?     Assuming: struct temp     {         int b;     }s[50];
A
s.b.[i];
B
s.[i].b;
C
s.b[i];
D
s[i].b;
Question 2
Comment on the output of this C code?
    #include 
    struct temp
    {
    int a;
    int b;
    int c;
    };
    main()
    {
    struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    }
A
No Compile time error, generates an array of structure of size 3
B
No Compile time error, generates an array of structure of size 9
C
Compile time error, illegal declaration of a multidimensional array
D
Compile time error, illegal assignment to members of structure
Question 3
Which of the following uses structure?
A
Array of structures
B
Linked Lists
C
Binary Tree
D
All of the mentioned
Question 4
 What is the correct syntax to declare a function foo() which receives an array of structure in     function?
A
void foo(struct *var);
B
void foo(struct *var[]);
C
void foo(struct var);
D
None of the mentioned
Question 5
What is the output of this C code? (Assuming size of int be 4)
    #include 
    struct temp
    {
    int a;
    int b;
    int c;
    } p[] = {0};
    main()
    {
    printf("%d", sizeof(p));
    }
A
4
B
12
C
16
D
Can’t be estimated due to ambigous initialization of array
Question 6
What is the output of this C code?
    #include 
    struct student
    {
    char *name;
    };
    struct student s[2];
    void main()
    {
    s[0].name = "alan";
    s[1] = s[0];
    printf("%s%s", s[0].name, s[1].name);
    s[1].name = "turing";
    printf("%s%s", s[0].name, s[1].name);
    }
A
alan alan alan turing
B
alan alan turing turing
C
alan turing alan turing
D
Run time error
Question 7
What is the output of this C code?
    #include 
    struct student
    {
    char *name;
    };
    struct student s[2], r[2];
    void main()
    {
    s[0].name = "alan";
    s[1] = s[0];
    r = s;
    printf("%s%s", r[0].name, r[1].name);
    }
A
alan alan
B
Compile time error
C
Varies
D
Nothing
Question 8
What is the output of this C code?
    #include 
    struct student
    {
    char *name;
    };
    void main()
    {
    struct student s[2], r[2];
    s[1] = s[0] = "alan";
    printf("%s%s", s[0].name, s[1].name);
    }
A
alan alan
B
Nothing
C
Compile time error
D
Varies
Question 9
What is the output of this C code?
    #include 
    struct student
    {
    };
    void main()
    {
    struct student s[2];
    printf("%d", sizeof(s));
    }
A
2
B
4
C
8
D
0
Question 10
What is the output of this C code?
    #include 
    struct point
    {
    int x;
    int y;
    };
    void foo(struct point*);
    int main()
    {
    struct point p1[]  =  {1, 2, 3, 4};
    foo(p1);
    }
    void foo(struct point p[])
    {
    printf("%d\n", p[1].x);
    }
A
Compile time error
B
3
C
2
D
1
Question 11
What is the output of this C code?
    #include 
    struct point
    {
    int x;
    int y;
    };
    void foo(struct point*);
    int main()
    {
    struct point p1[] = {1, 2, 3, 4};
    foo(p1);
    }
    void foo(struct point p[])
    {
    printf("%d\n", p->x);
    }
A
1
B
2
C
3
D
Compile time error
Question 12
What is the output of this C code?
    #include 
    struct point
    {
    int x;
    int y;
    };
    void foo(struct point*);
    int main()
    {
    struct point p1[] = {1, 2, 3, 4};
    foo(p1);
    }
    void foo(struct point p[])
    {
    printf("%d %d\n", p->x, ++p->x);
    }
A
1 2
B
22
C
Compile time error
D
Undefined behaviour
Question 13
What is the output of this C code?
    #include 
    struct point
    {
    int x;
    int y;
    } p[] = {1, 2, 3, 4, 5};
    void foo(struct point*);
    int main()
    {
    foo(p);
    }
    void foo(struct point p[])
    {
    printf("%d %d\n", p->x, p[2].y);
    }
A
1 0
B
Compile time error
C
1 somegarbagevalue
D
Undefined behaviour
Question 14
What is the output of this C code?
    #include 
    struct point
    {
    int x;
    int y;
    };
    void foo(struct point*);
    int main()
    {
    struct point p1[] = {1, 2, 3, 4, 5};
    foo(p1);
    }
    void foo(struct point p[])
    {
    printf("%d %d\n", p->x, p[3].y);
    }
A
Compile time error
B
1 0
C
1 somegarbagevalue
D
None of the mentioned
Question 15
What is the output of this C code?
    #include 
    struct point
    {
    int x;
    int y;
    };
    void foo(struct point*);
    int main()
    {
    struct point p1[] = {1, 2, 3, 4, 5};
    foo(p1);
    }
    void foo(struct point p[])
    {
    printf("%d %d\n", p->x, (p + 2).y);
    }
A
Compile time error
B
1 0
C
1 somegarbagevalue
D
Undefined behaviour
Question 16
What is the output of this C code?
    #include 
    struct point
    {
    int x;
    int y;
    };
    void foo(struct point*);
    int main()
    {
    struct point p1[] = {1, 2, 3, 4, 5};
    foo(p1);
    }
    void foo(struct point p[])
    {
    printf("%d %d\n", p->x, (p + 2)->y);
    }
A
Compile time error
B
1 0
C
1 somegarbagevalue
D
undefined behaviour
Question 17
What is the output of this C code?
    #include 
    struct student
    {
    char *c;
    };
    void main()
    {
    struct student s[2];
    printf("%d", sizeof(s));
    }
A
2
B
4
C
16
D
8



Check Your Answers:

  1. D
  2. A
  3. D
  4. A
  5. B
  6. A
  7. C
  8. C
  9. D
10. B
11. A
12. B
13. A
14. C
15. A
16.B


SHARE

Unknown

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment