NEW
Font size
WorksheetsC - Structures
Total questions: 20
Worksheet time: 20mins
Which of the following operation is illegal in structures?
Typecasting of structure
Pointer to a variable of same structure
Dynamic allocation of memory for structure
All of the mentioned
What is the size of a C structure?
C structure is always 128 bytes
Size of C structure is the total bytes of all elements of structure
Size of C structure is the size of largest element
None of the above
Which operator connects the structure name to its member name?
-
.
/
\
Which of the following cannot be a structure member?
Another structure
Array
Function
None of the mentioned
Number of bytes in memory taken by the below structure is?
struct test
{
int k;
char c;
};
Multiple of integer size
integer size+character size
Depends on the platform
Multiple of word size
Size of a union is determined by size of the
Biggest member in the union
First member in the union
Last member in the union
Sum of the sizes of all members
A C structure or User defined datatype is also called ________.
Derived data type
Secondary data type
Aggregate data type
All the above
Members of a union are accessed as_____________.
union-name.member
union-pointer->member
Both a & b
None of the mentioned
Choose a correct statement about C structures
Structure elements can be initialized at the time of declaration
Structure members can not be initialized at the time of declaration
Only integer members of structure can be initialized at the time of declaraion
None of the above
What is the output of C program?
#include <stdio.h>
int main()
{
structure hotel
{
int items;
char name[10];
}a;
strcpy(a.name, "TAJ");
a.items=10;
printf("%s", a.name);
return 0;
}
TAJ
Empty string
Compiler error
None of the above
What is the output of C program?
#include <stdio.h>
int main()
{
struct book
{
int pages;
char name[10];
}a;
a.pages=10;
strcpy(a.name,"Cbasics");
printf("%s=%d", a.name,a.pages);
return 0;
}
empty string=10
Cbasics=10
C=basics
Compiler error
What is the output of C program?
#include <stdio.h>
int main()
{
struct ship
{
int size;
char color[10];
}boat1, boat2;
boat1.size=10;
boat2 = boat1;
printf("boat2=%d",boat2.size);
return 0;
}
boat2=10
boat2=-1
boat2=0
Compiler error
What is the output of C program with structures?
#include <stdio.h>
int main()
{
struct ship
{
char color[10];
}boat1, boat2;
strcpy(boat1.color,"RED");
printf("%s ",boat1.color);
boat2 = boat1;
strcpy(boat2.color,"YELLOW");
printf("%s",boat1.color);
return 0;
}
RED RED
RED YELLOW
YELLOW YELLOW
Compiler error
What is the output of c program with structures?
#include <stdio.h>
int main()
{
struct tree
{
int h;
int w;
};
struct tree tree1={10};
printf("%d ",tree1.w);
printf("%d",tree1.h);
return 0;
}
0 0
10 0
0 10
10 10
What is the output of C program?
#include <stdio.h>
int main()
{
struct laptop
{
int cost;
char brand[10];
};
struct laptop L1={5000,"ACER"};
struct laptop L2={6000,"IBM"};
printf("Name=%s",L1.brand);
return 0;
}
Name=ACER
Name=
Compiler error
None of the above
What is the output of C program with Structure pointer in C?
#include <stdio.h>
int main()
{
struct books{
int pages;
char str[4];
}*ptr;
printf("%d",sizeof(ptr));
return 0;
}
2
6
7
4
What is the output of C program with structures pointers?
#include <stdio.h>
int main()
{
struct forest
{
int trees;
int animals;
}F1,*F2;
F1.trees=1000;
F1.animals=20;
F2=&F1;
printf("%d ",F2.animals);
return 0;
}
0
20
Compiler error
None of the above
What is the output of this C program?
int main()
{
struct bus
{
int seats;
}F1, *F2;
F1.seats=20;
F2=&F1;
F2->seats=15;
printf("%d ",F1.seats);
return 0;
}
15
20
0
Compiler Error
What is the output of C program with structure array pointers?
#include <stdio.h>
int main()
{
struct car
{
int km;
}*p1[2];
struct car c1={1234};
p1[0]=&c1;
printf("%d ",p1[0]->km);
return 0;
}
0
1
1234
Compiler error
What is a structure in C language?
A structure is a collection of elements that can be of same data type
A structure is a collection of elements that can be of different data type
Elements of a structure are called members
All the above
