WorksheetsStructures and Pointers in C
Total questions: 35
Worksheet time: 22mins
Which of the following are themselves a collection of different data types?
string
struct
char
all
Which operator connects the structure name to its member name?
-
=
.
>>
Which of the following cannot be a structure member?
another structure
array
Function
None
What is the output of this C code?
void main()
{
struct student
{
int no;
char name[20];
};
struct student s;
s.no = 8;
printf("%d", s.no);
}
Nothing
Compile error
8
Junk
Memory allocated for structure members are always contigious
True
False
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
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
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
The __________, also known as the address operator, returns the memory address of a variable.
asterisk (* )
ampersand ( & )
percent sign ( % )
exclamation point ( ! )
In a C Program if
int a = 5;
Int *ptr = &a;
then the printf statement with
&a, a, *ptr , ptr
adrress, Value, Value, Adress
address, value, value, value
all address
All values
In a C program,
int a = 20;
*ptr = &a;
**dptr = &ptr;
printf ("%d", **dptr);
prints
address of a
address of ptr
value of a
address of dptr
What does this command do?.
Creates a pointer of type integer that is initially pointing to null.
Creates a pointer of type integer that is initially pointing to 0.
Creates a pointer in the heap
None of the answers are valid
What will be output?
int i=10;
int *p;
p=&i;
i+=5;
printf("\n i=%d *p=%d", i,*p)
i=10, *p=10
i=10, *p=15
i=15, *p=15
i=15, *p=10
Code to change the 3rd array value to 50 using pointers
int main(){
int a[] = {10,20,30};
int *p = a;
----------------------;
}
p+3 = 50
*(p+3) = 50
*p+2 = 50
*(p+2) = 50
int main()
{
int arri[] = {1, 2 ,3};
int *ptri = arri;
printf("%d ", sizeof(arri));
printf("%d ", sizeof(ptri));
return 0;
}
3 3
12 12
12 4
4 4
What do the following declaration signify?
char *arr[10];
arr is a array of 10 character pointers.
arr is a array of function pointer.
arr is a array of characters.
arr is a pointer to array of characters.
What is the output of C program with arrays and pointers.?
int main()
{
int size=4;
int a[size];
a[0]=5;
a[1]=6;
a[2]=7;
a[3]=8;
printf("%d %d", *(a+2), a[1]);
}
8 6
7 6
6 6
Compiler error
Which of the following pointer is Wild
int *p;
int *q=&a;
int *v=NULL;
void *g;
If 5 is added to the address value 'A' of an integer variable the new address is
A +5
A+ 10
A+ 20
Data insufficient
Dynamic memory allocation occurs
when a new variable is created by the compiler
when a new variable is created at runtime
when a pointer fails to dereference the right variable
when a pointer is assigned an incorrect address
