Showing posts with label structure. Show all posts
Showing posts with label structure. Show all posts

Tuesday, May 11, 2010

Structure Comparison

) int main()
{
struct emp
{
char name[20];
int empno;

};

struct emp e1 = {"harrypotter", 1311};

struct emp e2 = e1;

if (e1==e2)
printf ("e1 and e2 are same");
else
printf ("e1 and e2 are different");

}

Choice:
a)e1 and e2 are same
b)e1 and e2 are different
c)Error
d)Segmentation fault

Wednesday, February 10, 2010

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

Sunday, January 10, 2010

What does the following program print?

#include

void main()
{

static struct S1
{
char c[4], *s;
} s1 = {"abc", "def"};

printf("%c %c\n", s1.c[0], *s1.s);
printf("%s %s", s1.c, s1.s);
}

a) Compiler error

b) a def
    abc def

c) a d
    abc def

d) a d
    a def


Monday, March 9, 2009

Declaring structure pointer

Suppose that you declare

struct x *xp;

without any definition of struct x. Is this legal? Under what circumstances would it be useful?

Answer: It is perfectly legal to refer to a structure which has not been "fleshed out," as long as the compiler is never asked to compute the size of the structure or generate offsets to any members. Passing around pointers to otherwise undefined structures is quite acceptable, and is a good way of implementing "opaque" data types in C.

Monday, May 19, 2008

A Structure

a. Can be read as a single entity
b. Cannot be read as a single entity
c. Can be displayed as a single entity
d. Has member variables that cannot be read individually