C Programming Multiple Choice Question - Structure And Union

This section focuses on the "Structure And Union" of the C programming. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Which of the following are themselves a collection of different data types?

A. String
B. Structures
C. Char
D. None of the above

View Answer


2. Which operator connects the structure name to its member name?

A. -
B. ->
C. .
D. both . and ->

View Answer


3. Which of the following cannot be a structure member?

A. Function
B. Array
C. Structure
D. None of the above

View Answer


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

View Answer


5. Union differs from structure in the following way

A. All members are used at a time
B. Only one member can be used at a time
C. Union cannot have more members
D. Union initialized all members as structure

View Answer


6. The size of the following union, where an int occupies 4 bytes of memory is

union demo
{
  float x;
  int y;
  char z[10];
};

A. 8 byte
B. 4 byte
C. 10 byte
D. 18 byte

View Answer


7. Members of a union are accessed as________________.

A. union-name.member
B. union-pointer->member
C. Both a & b
D. None of the mentioned

View Answer


8. It is not possible to create an array of pointer to structures.

A. TRUE
B. FALSE
C. May Be
D. Can't Say

View Answer


9. Which of the following statement is True?

A. User has to explicitly define the numeric value of enumerations
B. User has a control over the size of enumeration variables.
C. Enumeration can have an effect local to the block, if desired
D. Enumerations have a global effect throughout the file.

View Answer


10. size of union is size of the longest element in the union

A. Yes
B. No
C. May Be
D. Can't Say

View Answer


11. What is the similarity between a structure, union and enumeration?

A. All of them let you define new values
B. All of them let you define new data types
C. All of them let you define new pointers
D. All of them let you define new structures

View Answer


12. Which of the following share a similarity in syntax? 1. Union 2. Structure 3. Arrays 4. Pointers

A. 3 and 4
B. 1 and 2
C. 2 and 3
D. All of the above

View Answer


13. Size of a union is determined by size of the.

A. First member in the union
B. Last member in the union C. Biggest member in the union
C. Sum of the sizes of all members
D. Biggest member in the union

View Answer


14. Which operator connects the structure name to its member name?

A. -
B. .
C. Both (b) and (c)
D. None of the above

View Answer


15. How will you free the allocated memory ?

A. remove(var-name);
B. free(var-name);
C. delete(var-name);
D. dalloc(var-name);

View Answer


16. Which of the following accesses a variable in structure b?

A. b->var;
B. b.var;
C. b-var;
D. b>var;

View Answer


17. Which of the following accesses a variable in structure *b?

A. b->var;
B. b.var;
C. b-var;
D. b>var;

View Answer


18. Which of the following is a properly defined struct?

A. struct {int a;}
B. struct a_struct {int a;}
C. struct a_struct int a;
D. struct a_struct {int a;};

View Answer


19. Which properly declares a variable of struct foo?

A. struct foo;
B. struct foo var;
C. foo;
D. int foo;

View Answer


20. What is the output of this program?

#include <stdio.h>
struct test {
    int x = 0;
    char y = 'A';
};
int main()
{
    struct test t;
    printf("%d, %c", s.x, s.y);
    return 0;
}

A. 0
B. Error
C. garbage value garbage value
D. None of these

View Answer


21. What is the output of this program?

#include <stdio.h>
struct test {
    int x;
    char y;
} test;

int main()
{
    test.x = 10;
    test.y = 'A';
    printf("%d %c", test.x,test.y);
    return 0;
}

A. 0.416666666666667
B. garbage value garbage value
C. Compilation Error
D. None of these

View Answer


22. What is the output of this program?

#include <stdio.h>
struct result{
  char sub[20];
  int marks;
};
void main()
{
      struct result res[] = { {"Maths",100},
      {"Science",90},
      {"English",85}
      };
    printf("%s ", res[1].sub);
    printf("%d", (*(res+2)).marks);
}

A. Maths 100
B. Science 85
C. Science 90
D. Science 100

View Answer


23. What will be the size of the following structure?

		   
struct demo{
  int a;
  char b;
  float c;
}

A. 12
B. 8
C. 10
D. 9

View Answer


24. What is the output of this program?

#include <stdio.h>         
void main()
{
struct demo{
    char * a;
    int n;
};

struct demo p = {"hello", 2015};
struct demo q = p;
printf("%d", printf("%s",q.a));
}

A. hello
B. 5hello
C. hello5
D. 6hello

View Answer


25. What is the output of this program?

#include <stdio.h>
int main()
{
    union demo {
        int x;
        int y;
    };
 
    union demo a = 100;
    printf("%d %d",a.x,a.y);
}

A. 100 0
B. 100 100
C. 0 0
D. Compilation Error

View Answer


26. What is the output of this program?

#include <stdio.h>
int main()
{
    enum days {MON=-1, TUE, WED=4, THU, FRI, SAT};
    printf("%d, %d, %d, %d, %d, %d", MON, TUE, WED, THU, FRI, SAT);
    return 0;
}

A. -1 0 4 5 6 7
B. -1 0 1 2 3 4
C. 0 1 2 3 4 5
D. Error

View Answer


27. What is the output of this program?

#include <stdio.h>
int main(){
   struct simp 
	{
		int i = 6;
		char city[] = "chennai";
	};
	struct simp s1;
	printf("%d",s1.city);
	printf("%d", s1.i);
    return 0;
}

A. chennai 6
B. Nothing will be displayed
C. Runtime Error
D. Compilation Error

View Answer


28. What is the output of this program?

#include <stdio.h>
	struct 
{
	int i;
	float ft;
}decl;
int main(){
    decl.i = 4;
	decl.ft = 7.96623;
	printf("%d %.2f", decl.i, decl.ft);
	return 0;
}

A. 4 7.97
B. 4 7.96623
C. Compilation error
D. None of the above

View Answer


29. What is the output of this program?

void main()
  {
  struct bitfields {
  int bits_1: 2;
  int bits_2: 9;
  int bits_3: 6;
  int bits_4: 1;
  }bit;
  printf("%d", sizeof(bit));
}

A. 2
B. 3
C. 4
D. 0

View Answer


30. What is the output of this program?

#include <stdio.h>
int main(){
    struct leader
	{
	char *lead;
	int born;
	};
	struct leader l1 = {"AbdulKalam", 1931};
	struct leader l2 = l1;
	printf("%s %d", l2.lead, l1.born);
}

A. Compilation error
B. Garbage value 1931
C. AbdulKalam 1931
D. None of the above

View Answer


31. What is the output of this program?

#include <stdio.h>
struct employee
{
  char *empname;
  int salary;
};
int main()
{
  struct employee e, e1;
  e.empname = "Sridhar";
  e1 = e;
  printf("%s %s", e.empname, e1.empname);
  return 0;
}

A. Garbage value Sridhar
B. Sridhar Garbage value
C. Sridhar Sridhar
D. Compilation Error

View Answer


32. What is the output of this program?

#include <stdio.h>
struct student
{
  int no = 5;
  char name[20];
};
void main()
{
  struct student s;
  s.no = 8;
  printf("hello");
}

A. Nothing
B. Compile time error
C. hello
D. Varies

View Answer


33. What is the output of this program?

#include <stdio.h>
void main()
{
  struct number
  {
    int no;
    char name[20];
  };
  struct number s;
  s.no = 50;
  printf("%d", s.no);
}

A. Nothing
B. Compile time error
C. Junk
D. 50

View Answer


34. Number of bytes in memory taken by the below structure is

#include <stdio.h>
struct test
{
  int k;
  char c;
};

A. Multiple of integer size
B. Integer size+character size
C. Depends on the platform
D. Multiple of word size

View Answer


35. What is the output of this program?

#include <stdio.h>         
struct student
{
  char *c;
};
void main()
{
  struct student s[2];
  printf("%d", sizeof(s));
}

A. 2
B. 4
C. 16
D. 8

View Answer


36. Which of the following are incorrect syntax for pointer to structure?

    (Assuming struct temp{int b;}*my_struct;)

A. *my_struct.b = 10;
B. (*my_struct).b = 10;
C. my_struct->b = 10;
D. Both *my_struct.b = 10; and (*my_struct).b = 10;

View Answer


37. Which of the following is an incorrect syntax to pass by reference a member of a structure in a function?

(Assume: struct temp{int a;}s;)

A. func(&s.a);
B. func(&(s).a);
C. func(&(s.a));
D. None of the above

View Answer


38. 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.

A. Compiler can access entire structure from the function
B. Individual members address can be displayed in structure
C. Individual member can be passed by reference in a function
D. None of the above

View Answer


39. 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;

View Answer


40. The number of distinct nodes the following struct declaration can point to is

struct node
{
   struct node *left;
   struct node *centre;
   struct node *right;
};

A. 1
B. 2
C. 3
D. All of the above

View Answer






Also check :


Discussion



* You must be logged in to add comment.