Search Placementyogi.com
 

C Structures And Unions Objective Questions and Answers

  :: Topics ::

1

Below program compiles successfully.

#include<stdio.h>
int main()
{
  struct student
  {
    int id;
    char name[20];
   }

   struct student a;
   a.id=20;
}
A. True
B. False
See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

semicolon(;) is missing at end of structure declaration.

 
2

Does this program execute successfully and print 20, PlacementYogi ?

#include<stdio.h>
int main()
{
  struct student
  {
    int id;
    char *name;
   };
   struct student a[100];
   
   a[0].id=20;
   a[0].name="PlacementYogi";

   printf("%d,%s",a[0].id,a[0].name);
   return 0;
}
A. Yes
B. No
See Answer & Explanation Lets Discuss
Correct answer is : A
Explanation

We can create an array of structure type. This avoid the declaration of multiple structure variables.

 
3

What is the output of below c program?

#include<stdio.h>
int main()
{
  struct student
  {
    int id;
    char *name;
   };

   struct student *a,b 
   
   a->id=20;
   a->name="PlacementYogi";

   printf("%d,%s",a->id,a->name);
}
A.

20, PlacementYogi

B.

Compilation error

C.

Run time error : segmentation fault

See Answer & Explanation Lets Discuss
Correct answer is : C
Explanation
Note : Its correct to use ->( Arrow operator ) when accessing structure variable through pointer to structure.

In given question 'a' is declared as pointer of type student structure but it's not pointing to any memory location(structure variable). So its like pointing like no where or to some random memory location that does not exist. When we compile it, it compiles successfully but at run time it try to access some memory that does not exist,that results in segmentation fault error. 

 After struct student *a,b; if we add=> a=&b; then every thing will work fine.

 
 

Banner to LogicGuns.com

Hide Page Information

C Structures And Unions Objective Questions and Answers for Written Round Interview

Here you can find C Structures And Unions Objective Questions with answers and explanation. We have a vast collection of Objective Questions on Structures And Unions in C that will help you a lot!

Why learn C Structures And Unions?

Structures And Unions are an integral part of C and many Objective Questions in the written round are asked from this topic.In this section you can learn and practice C Structures And Unions (Objective Questions with Answers) to improve your skills in order to face the interview and clear campus and off-campus selection of TCS, Infosys, Wipro etc.

Where can I get C Structures And Unions Objective Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved C Structures And Unions Objective Questions and answers with explanation. Fully solved examples with detailed answer description, explanation are given and it would be easy to understand.Though we do not have pdf file for C Structures And Unions, We have quiz Objective Questions with answers to help you test yourself..

\n

Where can I get C Structures And Unions Interview Objective Questions and Answers (objective type, multiple choice)?

Here you can find objective type C Structures And Unions Objective Questions and answers for interview and entrance examination.Multiple Answers and true or false type Objective Questions are also provided.

How to solve C Structures And Unions problems?

You can easily solve all kind of Objective Questions based on C Structures And Unions by practicing the exercises (including shortcut Structures And Unions to solve problems) given below.