Welcome Guest | Sign in | Register

Home > C Programming > Structures > Questions and Answers

01. What is the output of this program?
main()
{
struct
{
int i;
}xyz;
(*xyz)->i=10;
printf("%d",xyz.i);
}
A. program will not compile B. 10
C. god only knows D. address of I

Answer and Explanation

Answer: 10

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. What is the output of this program?
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s;
printf("%d",s->x);
printf("%s",s->name);
}
A. 3 B. Compile Error
C. hello D. null

Answer and Explanation

Answer: Compile Error

Explanation:
You should not initialize structure variables in declaration.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. What is the output of this program?
main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}
A. No output B. Compiler Error
C. Null D. None of these

Answer and Explanation

Answer: Compiler Error

Explanation:
The structure yy is nested within structure xx. Hence, the elements are of yy are to be accessed through the instance of structure xx, which needs an instance of yy to be known. If the instance is created after defining the structure the compiler will not know about the instance relative to xx. Hence for nested structure yy you have to declare member.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04.  What is the output of this program?
struct aaa{
struct aaa *prev;
int i;
struct aaa *next;
};
main()
{
struct aaa abc,def,ghi,jkl;
int x=100;
abc.i=0;abc.prev=&jkl;
abc.next=&def;
def.i=1;def.prev=&abc;def.next=&ghi;
ghi.i=2;ghi.prev=&def;
ghi.next=&jkl;
jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;
x=abc.next->next->prev->next->i;
printf("%d",x);
}
A. 3 B. 100
C. 2 D. 0

Answer and Explanation

Answer: 2

Explanation:
above all statements form a double circular linked list;
abc.next->next->prev->next->i
this one points to "ghi" node the value of at particular node is 2.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. What is the output of this program?
struct point
{
int x;
int y;
};
struct point origin,*pp;
main()
{
pp=&origin;
printf("origin is(%d%d)\n",(*pp).x,(*pp).y);
printf("origin is (%d%d)\n",pp->x,pp->y);
}
A. origin is(0,0) origin is(0,1) B. origin is(1,1) origin is(0,0)
C. origin is(0,0) origin is(0,0) D. None of these

Answer and Explanation

Answer: origin is(0,0) origin is(0,0)

Explanation:
pp is a pointer to structure. we can access the elements of the structure either with arrow mark or with indirection operator.
Note:
Since structure pointer is globally declared x & y are initialized as zeroes

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. Which of the following accesses a variable in structure b?
A. b->var; B. b.var;
C. b-var; D. b>var;

Answer and Explanation

Answer: b.var;

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. Which of the following is a properly defined struct?
A. struct {int a;} B. struct a_struct {int a;}
C. struct a_struct int a; D. struct a_struct {int a;};

Answer and Explanation

Answer: struct a_struct {int a;};

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. Which properly declares a variable of struct foo?
A. struct foo; B. struct foo var;
C. foo; D. int foo;

Answer and Explanation

Answer: struct foo var;

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. Which of the following is a properly defined struct?
A. struct {int a;} B. struct a_struct {int a;}
C. struct a_struct int a; D. struct a_struct {int a;};

Answer and Explanation

Answer: struct a_struct {int a;};

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. A structure called record which holds an integer called loop, a character array of 5 elements called word, and a float called sum, looks like
A. Structure 1
struct record {
int loop;
char word[5];
float sum;
};
B. Structure 2
type structure record {
loop : integer;
word : array[0..4] of char;
sum : real;
};
C. Structure 3
type record {
integer loop;
char word[4];
float sum;
}
D. None of these

Answer and Explanation

Answer: Structure 1
struct record {
int loop;
char word[5];
float sum;
};

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.