WorksheetsStructure C
Total questions: 60
Worksheet time: 40mins
Which of the following are themselves a collection of different data types?
string
char
struct
all
Which operator connects the structure name to its member name?
-
.
=
>>
Which of the following cannot be a structure member?
another structure
Function
array
None
Which of the following structure declaration will throw an error?
struct temp{ } s;
main(){}
struct temp{ };
struct temp s;
main(){ }
struct temp s;
struct temp{ };
main(){ }
None
What is the output of this C code?
Nothing
Compile error
8.0
8
Size of a union is determined by size of the.
First member in the union
Last member in the union
Biggest member in the union
Sum of the sizes of all members
Assuming size of long int is 4 bytes, what will be the output for:
typedef long long int L = 24;
printf("Size of long long int is :");
printf("%d",sizeof(L));
24
4
8
Error
What will be the output ?
Name:
Subject:
Percentage: 86.50000
Name:Raju
Subject:
Percentage: 86.50000
Name: Raju
Subject: Maths
Percentage: 86.50000
Error
Memory allocated for structure members are always contigious ?
True
False
What do you understand by:
void update(struct student *s);
update is a function that takes an argument as pointer to structure variable and returns nothing
update is a method that takes structure type variable as parameter
Error, we cannot pass structure variable as pointer to a function
update takes pointer argument but it cannot return void
Which keyword is used to declare structure variable?
Structure
struct
s
sruct s
Structure is a variable which holds____________________
Different data types
similar data types
only int and float
only int and char
which of the following structure definition is correct one?
struct stu
{
----}s
struct stu
{
----}s;
struct stu
{
----};
both b and c
How to access data member of a structure?
s->rollno
s.rollno
rollno
None of the above
Is it necessary to create a structure variable to access its members? True or False
True
False
What is array of structure?
Single structure
Collection of structure
Different structure
Collection of data types
Is it possible to assign values of data members with the structure variable?
True
False
Below code is, Pointer structure variable declaration and Initialization. Which is correct?
struct *p=&s;
struct stud *p=&s;
struct stud p=&s;
struct stud *p=s;
Which operator is used to access data member of a structure using pointer variable?
arrow
->
dot operator
both a and b
Pointer variable to a structure holds address of ___________
part of a structure
structure
datamember
values
Which of the following are themselves a collection of different data types?
string
structures
char
all of the mentioned
User-defined data type can be derived by___________
struct
enum
typedef
all of the mentioned
What will be the output of the following C code?
#include <stdio.h>
struct student
{
int no;
char name[20];
}
void main()
{
struct student s;
s.no = 8;
printf("hello");
}
Compile time error
Nothing
hello
Varies
Which of the following return-type cannot be used for a function in C?
char *
struct
void
none of the mentioned
Which of the following is not possible under any scenario?
s1 = &s2;
s1 = s2;
(*s1).number = 10;
None of the mentioned
Which of the following operation is illegal in structures?
Typecasting of structure
Pointer to a variable of the same structure
Dynamic allocation of memory for structure
All of the mentioned
Comment on the output of the following C code.
#include <stdio.h>
struct temp
{
int a;
int b;
int c;
};
main()
{
struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
}
No Compile time error, generates an array of structure of size 3
No Compile time error, generates an array of structure of size 9
Compile time error, illegal declaration of a multidimensional array
Compile time error, illegal assignment to members of structure
Which of the following uses structure?
Array of structures
Linked Lists
Binary Tree
All of the mentioned
What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student m;
struct student *s = &m;
s->c = "hello";
printf("%s", m.c);
}
Run time error
Nothing
hello
Varies
Which of the following is not possible regarding the structure variable?
A structure variable pointing to itself
A structure variable pointing to another structure variable of same type
2 different type of structure variable pointing at each other
None of the mentioned
Which of the following will stop the loop at the last node of a linked list in the following C code snippet?
struct node
{
struct node *next;
};
while (p != NULL)
{
p = p->next;
}
while (p->next != NULL)
{
p = p->next;
}
while (1)
{
p = p->next;
if (p == NULL)
break;
}
All of the mentioned
What will be the output of the following C code?
#include <stdio.h>
struct student
{
char a[5];
};
void main()
{
struct student s[] = {"hi", "hey"};
printf("%c", s[0].a[1]);
}
h
i
e
y
What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *a[3] = {"hello", "this"};
printf("%s", a[1]);
}
hello
Varies
this
Compile time error
What will be the output of the following C code?
#include <stdio.h>
void main()
{
int lookup[100] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
printf("%d", lookup[3]);
}
2
4
Compile time error
3
Which algorithm is used for searching in the table?
List search
Informed search
Hash search
Adversarial search
What will be the output of the following C code?
#include <stdio.h>
union stu
{
int ival;
float fval;
};
void main()
{
union stu r;
r.ival = 5;
printf("%d", r.ival);
}
9
Compile time error
16
5
A union cannot be nested in a structure
True
False
size of union is size of the longest element in the union
Yes
No
Which of the following share a similarity in syntax?
1. Union,
2. Structure,
3. Arrays and
4. Pointers
3 and 4
1 and 2
1 and 3
1, 3 and 4
What is the correct syntax to initialize bit-fields in an structure?
struct temp
{
unsigned int a : 1;
}s;
struct temp
{
unsigned int a = 1;
}s;
struct temp
{
unsigned float a : 1;
}s;
None of the mentioned
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
