Machine-translated by Google. Questions are authored in English.
Top

Discussion

Anyone of the followings can be used to declare a node for a singly linked list. If we use the first declaration, “struct node * nodePtr;” would be used to declare pointer to a node. If we use the second declaration, “NODEPTR nodePtr;” can be used to declare pointer to a node.

/* First declaration */
struct node {
int data;
struct node * nextPtr;
};
 
/* Second declaration */
typedef struct node{
int data;
NODEPTR nextPtr;
} * NODEPTR;

 

  • A.TRUE
  • B.FALSE

Answer: B

Correct answer: FALSE

The second declaration is broken: NODEPTR is used inside the structure to declare nextPtr, but the typedef that defines NODEPTR is not complete until the closing brace. A name cannot be used before it exists, so the compiler rejects it. The self-reference has to be written as struct node *nextPtr;.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.