Sail E0 Webinar

MCQs

Total Questions : 72 | Page 6 of 8 pages
Question 51.

What is the similarity between a structure, union and enumeration?


  1.    All of them let you define new values
  2.    All of them let you define new data types
  3.    All of them let you define new pointers
  4.    All of them let you define new structures
 Discuss Question
Answer: Option B. -> All of them let you define new data types

No answer description available for this question. 


Question 52.

What will be output if you compile following c code ?


#include<stdio.h>
struct
{
int i;
float f;
};
void main()
{
int i=5;
float f=9.76723;
printf("%d %.2f",i,f);
}


  1.    Compile Error
  2.    5 9.76723
  3.    5 9.76
  4.    5 9.77
 Discuss Question
Answer: Option D. -> 5 9.77

Both <struct type name> and <structure variables> are optional. Thus the structure
defined in the above program has no use and program executes in the normal way.


Question 53.

What will be output if you compile following c code ?


#include<stdio.h>
typedef struct
{
int i;
float f;
}temp;
void alter(temp tmp,int x,float y)
{
tmp.i=x;
tmp.f=y;
return tmp;
}
void main()
{
temp a={111,777.007};
printf("%d %.3f\n",a.i,a.f);
alter(&a,222,666.006);
printf("%d %.3f",a.i,a.f);
}




  1.    Compile Error
  2.    111 777.007222 666.006
  3.    111 777.01222 666.01
  4.    None of these
 Discuss Question
Answer: Option B. -> 111 777.007222 666.006

This program illustrates the transfer of a structure to a function by value. Also the altered structure is now returned directly to the calling portion of the program.



Question 54.

What will be output if you compile following c code ?


#include<stdio.h>
struct first
{
int a;
float b;
}s1={32760,12345.12345};
typedef struct
{
char a;
int b;
}second;
struct my_struct
{
float a;
usigned int b;
};
typedef struct my_struct third;
void main()
{
struct second s2={'A',- -4};
third s3;
s3.a=~(s1.a-32760);
s3.b=-++s2.b;
printf("%d %.2f\n%c %d\n%.2f %u",(s1.a)--,s1.b+0.005,s2.a+32,s2.b,++(s3.a),--s3.b);
}


  1.    Compile Error
  2.    32760 12345.12 A 4 1 -5
  3.    32760 12345.13 a -5 0.00 65531
  4.    32760 12345.13 a 5 0.00 65530
 Discuss Question
Answer: Option D. -> 32760 12345.13 a 5 0.00 65530

 Illustrating 3 different ways of declaring the structres : first, second and third are the user-defined structure type. s1, s2 and s3 are structure variables. Also an expression of the form ++variable.member is equivalent to  ++(variable.member), i.e. ++ operator will apply to the structure member, not the entire structure variable.


Question 55.

How will you free the allocated memory ?


  1.    remove(var-name);
  2.    free(var-name);
  3.    delete(var-name);
  4.    dalloc(var-name);
 Discuss Question
Answer: Option B. -> free(var-name);

No answer description available for this question. 


Question 56.

What will be output if you compile following c code ?


#include<stdio.h>
typedef struct
{
int i;
float f;
}values;
void main()
{
static values var={555,67.05501};
printf("%2d %.2f",var.i,var.f);
}


  1.    Compile Error
  2.    55 67.05
  3.    555 67.06
  4.    555 67.05
 Discuss Question
Answer: Option C. -> 555 67.06

In the above program, values is the user-defined structure type or the new user-defined data type. Structure  variables can then be defined in terms of the new data type.


Question 57.

What will be output if you compile following c code ?


#include<stdio.h>
struct my_struct
{
int i=7;
float f=999.99;
}var;
void main()
{
var.i=5;
printf("%d %.2f",var.i,var.f);
}


  1.    Compile error
  2.    7 999.99
  3.    5 999.99
  4.    None of these
 Discuss Question
Answer: Option A. -> Compile error

C language does not permit the initialization of individual structure members within the template. The initialization must be done only in the declaration of the actual variables.


Question 58.

What will be output if you compile following c code ?


#include<stdio.h>
struct
{
int i,val[25];
float f;
}var={1,2,3,4,5,6,7,8,9},*vptr=&var;
void main()
{
printf("%d %d %d\n",var.i,vptr->i,(*vptr).i);
printf("%d %d %d %d %d %d",var.val[4], var.val+4), vptr->val[4],*(vptr->val+4),
(*vptr).val[4], *((*vptr).val+4));
}


  1.    Compile Error
  2.    1 1 16 6 6 6 6 6
  3.    1 1 15 5 5 5 5 5
  4.    None of these
 Discuss Question
Answer: Option B. -> 1 1 16 6 6 6 6 6

Since value of the member 'i' can be accessed using var.i, vptr->i and (*vptr).i  Similarly 5th value of the member 'val' can be accessed using var.val[4], *(var.val+4), vptr->val[4], *(vptr->val+4), (*vptr).val[4] and *((*vptr).val+4)


Question 59.

What will be output if you compile following c code ?


#include<stdio.h>
typedef struct
{
int i;
float f;
}temp;
void alter(temp *ptr,int x, float y)
{
ptr->i=x;
ptr->f=y;
}
void main()
{
temp a={111,777.007};
printf("%d %.2f\n",a.i,a.f);
alter(&a,222,666.006);
printf("%d %.2f",a.i,a.f);
}




  1.    Compile Error
  2.    111 777.007 222 666.006
  3.    111 777.01 222 666.01
  4.    None of these
 Discuss Question
Answer: Option C. -> 111 777.01 222 666.01

This program illustrates the transfer of a structure to a function by passing the structure's address (a pointer) to the function.



Question 60.

What will be output if you compile following c code ?


#include<stdio.h>
struct names
{
char str[25];
struct names *next;
};
typedef struct names slist;
void main()
{
slist *list,*temp;
list=(slist *)malloc(sizeof(slist)); // Dynamic Memory Allocation
strcpy(list->str,"Hai");
list->next=NULL;
temp=(slist *)malloc(sizeof(slist)); // Dynamic Memory Allocation
strcpy(temp->str,"Friends");
temp->next=list;
list=temp;
while (temp != NULL)
{
printf("%s",temp->str);
temp=temp->next;
}
}


  1.    Compile Error
  2.    HaiFriends
  3.    FriendsHai
  4.    None of these
 Discuss Question
Answer: Option C. -> FriendsHai

It is sometimes desirable to include within a structure one member i.e. a pointer to the parent structure type. Such structures are known as Self-Referencial structures. These structures are very useful in applications that involve linked data structures, such as lists and trees. [A linked data structure is not confined to some maximum number of components. Rather, the data structure can expand or contract in size as required.]


Latest Videos

Latest Test Papers