This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1To create synonym for data type use ___________.
Option B
In C/C++, sometimes data types have long or complex names, which makes code harder to read. To solve this, we can create a new name (synonym) for an existing data type. The keyword typedef is used to define a new name for an existing data type.
E.g.:
typedef unsigned int uint;
uint a=10;
Q: 2Output 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);
}
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.
Q: 3What will be the output of the following code?
#include<stdio.h>
struct info
{
int x;
};
int main()
{
struct info a = {10};
struct info b = a;
b.x = 20;
printf(“%d %d”, a.x,b.x);
return 0;
}
Option C
As we know, structure variables in C are copied by value, not by reference. When struct info b = a; is executed, the value of a.x (10) is copied into b.x. Later, changing b.x = 20 does not affect a.x, which remains 10. Therefore, the output of the program is 10 20.
You have reached the end of this topic. Continue learning with the next topic below.
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.