FAQS ON STRUCTURES AND UNIONS IN C LANAGUAGE
FAQS ON STRUCTURES
AND UNIONS IN C LANAGUAGE
1. Can we initialize members here in
structure or union in c language?
A. We can only
declare members inside the structure and union, initialization of member with
declaration is not allowed in structure and union declaration.
2. 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
3. A union cannot be nested
in a structure True or false
A.false.
4. Which of the following
cannot be a structure member?
A. Another structure
B. Function
C. Array
D. None of the mentioned
5. Which among the following is never possible
in C when members in a structure are same as that in a union?
//Let
P be a structure
//Let Q be a union
//Let Q be a union
a. sizeof(P) is greater than sizeof(Q)
b. sizeof(P) is equal to sizeof(Q)
c. sizeof(P) is less than to sizeof(Q)
d. None of the above
6.
3) Which
among the following is never possible in C when members are different in a
structure and union?
//Let P be a structure
//Let Q be a union
//Let P be a structure
//Let Q be a union
a. sizeof(P) is greater than sizeof(Q)
b. sizeof(P) is less than sizeof(Q)
c. sizeof(P) is equal to sizeof(Q)
d. None of the above
7.
Which of the following operation is illegal in structures?
a) Typecasting of structure
b) Pointer to a variable of same structure
c) Dynamic allocation of memory for structure
d) All of the mentioned
a) Typecasting of structure
b) Pointer to a variable of same structure
c) Dynamic allocation of memory for structure
d) All of the mentioned
8.
User-defined data type can be derived
by___________
a.struct
b.enum
c.typedef
d.all of the mentioned
9.
Which of the following structure declaration will throw an error?
a.struct temp{}s; main(){}
b.struct temp{}; struct temp s; main(){}
c.struct temp s; struct temp{}; main(){}
d.None of the mentioned
10. Which keyword is used to define a new structure?
A. struct
B. structure
C. typedef
D. none of the above
11.
__________ is a keyword used in C
language to assign alternative names to existing types?
A. struct
B. typedef
C. union
D. none of the abov
12. What will be the output of following code?
main()
{
struct student
{
char name[20];
int roll;
};
struct student s1 = { "rise", 8 };
struct student s2 = s1;
printf("%s", s2.name);
}
A. Error: Invalid structure assignment
B. No output
C. rise
D. rise 8
13. What will be the output of the program?
#include<stdio.h>
struct course
{
int courseno;
char coursename[25];
};
int main()
{
struct course c[] = {
{102, "C"},
{103, "C++"},
{104, "Java"}
};
printf("%d ",
c[1].courseno);
printf("%s\n",
(*(c+2)).coursename);
return 0;
}
A. 102 C
B. 103 C++
C. 103 Java
D. 104 Java
14. Point out the error in the code?
struct Student
{
char[20] name;
int rollno;
struct Student s2;
};
A. Error: in structure
declaration
B. Linker Error
C. No Error
D. None of above
15.
The .(dot) operator can be used to
access structure elements using a structure variable. True or False?
A. True
B. False
16. The size of a union is equal to __________?
A. size of the largest element in
the union
B. size of the smallest element in the union
C. combination of all the element of union
D. none of the above
17.
What will be the output of following
code?
main()
{
union std
{
int x;
int y;
};
union std s1;
s1.x =10;
s1.y =20;
printf("%d
%d\n",s1.x, s1.y);
return 0;
}
A. error
B. 20 20
C. only 20
D. none of the above
18. Is it necessary that the size of all elements in a union should be
same?
A. Yes
B. No
19. Which of the following accesses a variable in structure b?
A. b->var;
B. b.var;
C. b-var;
D. b>var;
20. Which of the following accesses a variable in a pointer to a
structure, *b?
A. b->var;
B. b.var;
C. b-var;
D. b>var;
21. 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;};
Comments
Post a Comment