Log In Register

Units


Pointer To Structures - Questions and Answers

 

Practice these Pointer To Structures under C Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Pointer To Structures for following purpose.


– Anyone who is wishing to increase their perfect knowledge of Pointer To Structures of C Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge C Programming specifically Pointer To Structures.
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Pointer To Structures under C Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  Pointer To Structures topic of C Programming:

 

1.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int x[2];
  5.     };
  6.     struct q
  7.     {
  8.         int *x;
  9.     };
  10.     int main()
  11.     {
  12.         struct p p1 = {1, 2};
  13.         struct q *ptr1;
  14.         ptr1->x = (struct q*)&p1.x;
  15.         printf("%d\n", ptr1->x[1]);
  16.     }

Answer: Option C

Explanation:

2.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     int main()
  8.     {
  9.         struct p p1[] = {1, 2, 3, 4, 5, 6};
  10.         struct p *ptr1 = p1;
  11.         printf("%d %d\n", ptr1->x, (ptr1 + 2)->x);
  12.     }

Answer: Option D

Explanation:

3.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     typedef struct p* q*;
  8.     int main()
  9.     {
  10.         struct p p1[] = {1, 92, 3, 94, 5, 96};
  11.         q ptr1 = p1;
  12.         printf("%d\n", ptr1->x);
  13.     }

Answer: Option D

Explanation:

4.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         char *c;
  5.     };
  6.     void main()
  7.     {
  8.         struct student *s;
  9.         s->c = "hello";
  10.         printf("%s", s->c);
  11.     }

Answer: Option C

Explanation:

5.

Comment on the output of this C code?

  1.     #include <stdio.h>
  2.     struct temp
  3.     {
  4.         int a;
  5.     } s;
  6.     void change(struct temp);
  7.     main()
  8.     {
  9.         s.a = 10;
  10.         change(s);
  11.         printf("%d\n", s.a);
  12.     }
  13.     void change(struct temp s)
  14.     {
  15.         s.a = 1;
  16.     }

Answer: Option D

Explanation:

6.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     int main(){
  8.         struct p p1[] = {1, 92, 3, 94, 5, 96};
  9.         struct p *ptr1 = p1;
  10.         int x = (sizeof(p1) / sizeof(struct p));
  11.         printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x);
  12.     }

Answer: Option A

Explanation:

7.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     int main()
  8.     {
  9.         struct p p1[] = {1, 92, 3, 94, 5, 96};
  10.         struct p *ptr1 = p1;
  11.         int x = (sizeof(p1) / sizeof(ptr1));
  12.         if (x == 1)
  13.             printf("%d\n", ptr1->x);
  14.         else
  15.             printf("false\n");
  16.     }

Answer: Option B

Explanation:

8.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     void foo(struct p* );
  8.     int main()
  9.     {
  10.         typedef struct p* q;
  11.         struct p p1[] = {1, 92, 3, 94, 5, 96};
  12.         foo(p1);
  13.     }
  14.     void foo(struct p* p1)
  15.     {
  16.         q ptr1 = p1;
  17.         printf("%d\n", ptr1->x);
  18.     }

Answer: Option C

Explanation:

9.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         char *c;
  5.     };
  6.     void main()
  7.     {
  8.         struct student m;
  9.         struct student *s = &m;
  10.         (*s).c = "hello";
  11.         printf("%s", m.c);
  12.     }

Answer: Option A

Explanation:

10.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     int main()
  8.     {
  9.         struct p p1[] = {1, 92, 3, 94, 5, 96};
  10.         struct p *ptr1 = p1;
  11.         int x = (sizeof(p1) / 3);
  12.         if (x == sizeof(int) + sizeof(char))
  13.             printf("%d\n", ptr1->x);
  14.         else
  15.             printf("falsen");
  16.     }

Answer: Option A

Explanation:

11.

Which of the following structure declaration doesn’t require pass-by-reference?

Answer: Option A

Explanation:

12.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         char *c;
  5.     };
  6.     void main()
  7.     {
  8.         struct student n;
  9.         struct student *s = &n;
  10.         (*s).c = "hello";
  11.         printf("%p\n%p\n", s, &n);
  12.     }

Answer: Option A

Explanation:

13.

For the following function call which option is not possible?
    func(&s.a); //where s is a variable of type struct and a is the member of the struct.

Answer: Option C

Explanation:

14.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int x[2];
  5.     };
  6.     struct q
  7.     {
  8.         int *x;
  9.     };
  10.     int main()
  11.     {
  12.         struct p p1 = {1, 2};
  13.         struct q *ptr1 = (struct q*)&p1;
  14.         ptr1->x = (struct q*)&p1.x;
  15.         printf("%d\n", ptr1->x[0]);
  16.     }

Answer: Option D

Explanation:

15.

Which of the following are incorrect syntax for pointer to structure?
    (Assuming struct temp{int b;}*my_struct;)

Answer: Option D

Explanation: