0
0
Cprogramming~10 mins

Accessing structure members - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to access the member 'age' of the struct variable 'person'.

C
int age = person.[1];
Drag options to blanks, or click blank then click option'
Aname
Bheight
Cage
Dweight
Attempts:
3 left
💡 Hint
Common Mistakes
Using the arrow operator (->) instead of the dot operator for a struct variable.
Trying to access a member that does not exist in the struct.
2fill in blank
medium

Complete the code to access the member 'salary' of the struct pointer 'empPtr'.

C
float sal = empPtr[1]salary;
Drag options to blanks, or click blank then click option'
A*
B->
C.
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using the dot operator with a struct pointer.
Dereferencing the pointer manually and then using dot operator incorrectly.
3fill in blank
hard

Fix the error in accessing the 'id' member from the struct pointer 'studentPtr'.

C
int studentId = studentPtr[1]id;
Drag options to blanks, or click blank then click option'
A.
B&
C*
D->
Attempts:
3 left
💡 Hint
Common Mistakes
Using the dot operator with a pointer.
Trying to dereference the pointer incorrectly.
4fill in blank
hard

Fill the blank to correctly access the 'grade' member of the struct pointer 'ptr'.

C
char grade = (*ptr)[1]grade;
Drag options to blanks, or click blank then click option'
A.
B*
C->
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using arrow operator after dereferencing.
Not dereferencing the pointer before using dot operator.
5fill in blank
hard

Fill the blanks to create a pointer to struct 'Book' and access its 'title' member.

C
struct Book [1]bookPtr = &book;
char* title = bookPtr->title;
Drag options to blanks, or click blank then click option'
A*
B->
C.
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot operator to access members through a pointer.
Not declaring the pointer correctly.