Exam 1 Flashcards
(61 cards)
True or False
A struct data type can include variables.
True
True or False
A struct data type include functions.
True
Variables declared in a struct data type are called
Data Fields / Data Members
Functions declared in a struct data type are called
Member Functions
True or False
A function prototype require names of parameter variables
False
Why don’t function prototypes require names of parameter variables?
Variable names are not required in the function prototype. The compiler will ignore them. This also means that the variable names used in the function prototype do not need to match those used in the actual function itself.
When you define a new data type, Role or Employee, in our projects, in a separate header file, what preprocessing directives need to be added?
endif
#ifndef EMPLOYEE_H #define EMPLOYEE_H
Explain the reason why you include preprocessing directives
endif specifies the end of a conditional directive
This prevent from the multiple inclusion of same header file multiple time.
The #ifndef , if not defined, directive checks if the identifier has not been defined, or if its definition has been removed with #undef, the condition is true (nonzero). Otherwise, the condition is false (0).
The #define creates a macro, which is the association of an identifier or parameterized identifier with a token string. After the macro is defined, the compiler can substitute the token string for each occurrence of the identifier in the source file.
When a singly linked list is used to store a collection of data items, each data item is stored in a _________, which includes an additional variable whose data type is a _______________.
Node , Node pointer
If you keep a variable that points to ________ , you can visit each data item in a single linked list.
Head
The arrow operator (->) is used when _______________
The arrow operator is used with a pointer to an object.
To access members of a structure through a pointer
a->b is the same notation as (*a).b
. Takes precedence so you have to () to do *a first.
-> is short hand
In a singly linked list, the pointer in the last node in the list typically points to ________
NULL
If you have a node pointer named head, which is pointing to a valide node, how do you access the member variable in the node named item?
A. head.item B. *head.item C. (*head).item D. head->item E. All of the above F. A or B G. C or D
G. C or D
(*head).item
head->item
Given the following declarations, how would you know if head is pointing to an empty list?
struct Node { int number; Node* next; };
Node* head; // some other code here
A. if(head->next == NULL) B. if(head == null) C. if(head == NULL) D. if(head->next==null); E. A and D F. B and C
C. if(head == NULL)
The actual value of NULL is
A. -1
B. 0
C. 99999
D. -99
B. 0
When do you use typedef? Write a code of an example
Define an alias of existing data type
typedef Employee EMP;
Which of the following loops correctly uses inter in order to move through the nodes of the linked list?
Node *iter;
A. while(iter != NULL)
iter++;
B. while(iter != NULL)
iter = iter->link;
C. for(iter =NULL; iter != NULL; iter = iter->link)
D. for(iter = head; iter != NULL; iter = iter->link)
D. for(iter = head; iter != NULL; iter = iter->link)
__________ is to create an instance and initialize data meme era of a struct data type
Constructor
The name of a constructor of a struct data type named Employee is ____________
Employee
The return of a construct of a struct data type named Employee is __________
none
The constructor of a struct data type named Employee without parameter variables is called _______________
Default constructor
Can a struct data type have multiple constructors ?
Yes
Explain why a struct data type have multiple constructors
Constructors are member functions. A function can be overloaded
How do you identify which constructor of a struct data type is called when an instance of the type is created?
Node* p1 = new node; Node* p2 = new node(e);
Node(EMP);