Structure and Union - C programming (MCQ)

31. What is the output of this program?

#include<stdio.h>
struct employee
{
char *empname;
int salary;
};
int main()
{
struct employee e, e1;
e.empname = "Sridhar";
e1 = e;
printf("%s %s", e.empname, e1.empname);
return 0;
}

A. Garbage value Sridhar
B. Sridhar Garbage value
C. Sridhar Sridhar
D. Compilation Error

View Answer


32. What is the output of this program?

#include <stdio.h>
struct student
{
int no = 5;
char name[20];
};
void main()
{
struct student s;
s.no = 8;
printf("hello");
}



A. Nothing
B. Compile time error
C. hello
D. Varies

View Answer


33. What is the output of this program?

#include <stdio.h>
void main()
{
struct number
{
int no;
char name[20];
};
struct number s;
s.no = 50;
printf("%d", s.no);
}

A. Nothing
B. Compile time error
C. Junk
D. 50

View Answer


34. Number of bytes in memory taken by the below structure is

#include <stdio.h>
struct test
{
int k;
char c;
};

A. Multiple of integer size
B. Integer size+character size
C. Depends on the platform
D. Multiple of word size

View Answer


35. What is the output of this program?

#include<stdio.h>
struct student
{
char *c;
};
void main()
{
struct student s[2];
printf("%d", sizeof(s));
}

A. 2
B. 4
C. 16
D. 8

View Answer


36. Which of the following are incorrect syntax for pointer to structure?

    (Assuming struct temp{int b;}*my_struct;)

A. *my_struct.b = 10;
B. (*my_struct).b = 10;
C. my_struct->b = 10;
D. Both *my_struct.b = 10; and (*my_struct).b = 10;

View Answer


37. Which of the following is an incorrect syntax to pass by reference a member of a structure in a function?

(Assume: struct temp{int a;}s;)

A. func(&s.a);
B. func(&(s).a);
C. func(&(s.a));
D. None of the above

View Answer


38. For the following function call which option is not possible?
func(&s.a); //where s is a variable of type struct and a is the member of the struct.

A. Compiler can access entire structure from the function
B. Individual member’s address can be displayed in structure
C. Individual member can be passed by reference in a function
D. None of the above

View Answer


39. The correct syntax to access the member of the ith structure in the array of structures is?

Assuming: 
struct temp
{
int b;
}s[50];

A. s.b.[i];
B. s.[i].b;
C. s.b[i];
D. s[i].b;

View Answer


40. The number of distinct nodes the following struct declaration can point to is

struct node
{
struct node *left;
struct node *centre;
struct node *right;
};

A. 1
B. 2
C. 3
D. All of the above

View Answer







Also check :


Discussion


* You must be logged in to add comment.