Output of the linked list node access in the following code:
struct node
{
int data;
struct node* next;
};
int main()
{
struct node n1 = {10,NULL};
struct node n2 = {20,NULL};
n1.next = &n2;
printf(“%d”, n1.data+n1.next->data);
}
10
20
NULL
30
[ Option D ]
In this program, n1 is initialized with data 10 and n2 with data 20. Then n1.next is set to point to n2. In the printf statement, n1.data gives 10 and n1.next->data accesses the data of n2, which is 20. Their sum is 30, so the output is 30.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.