TopBottom

Followers



Click on more
SUBSCRIBE

Enter your email address:

Delivered by FeedBurner



VIDEO

Announcement: wanna exchange links? contact me at ravikrak@yahoo.com

Questions On Pointers Through Structures

Posted by Ravi Kumar at Monday, September 26, 2011
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

1.Can a structure contain a pointer to itself ?
Ans:Certainly such structures are known as self
referential structures

2.What would be the output of the following program ?
main( )
{
struct emp
{
char *n;
int age;
}

struct emp e1={"dravid",123};
struct emp e2=e1;
strupr(e2.n);
prntf("\n%s",e1n);
}
Ans: DRAVID
3.If the following structure is written to a file usng
fwrite( ) ,can fread( ) read it back successfully ?
Ans: No,Since the structure contains a char pointer
while writting the structure to
the disk using fwrite( )
only the value stored in the pointer would get written.
When this structure is read back the address would be
read back but it is quite unlikely that the desired
string would be present at this adress in memory.
4.What is the output of the following program:
main()
{
struct a
{
char ch[7];
char *str;
};
static struct a s1={"Nagpur","Bombay"};
printf("%c%c\n",s1.ch[0],*s1.str);
printf("%s%s\n",s1.ch,s1.str);
}
Output: N B
Nagpur Bombay
5.what is the output of the following program?
main()
{
struct s1
{
char *z;
int i;
struct s1 *p;
};
static struct s1 a[]={
{"Nagpur",1,a+1};
{"Raipur",2,a+2};
{Kanpur",3,a}
};
struct s1 *ptr=a;
printf("%s%s%s\n",a[0].z,ptr->z,a[2]p-z);
}
6.What is the output of the following program?
main( )
{
struct node
{
int data;
struct node *link;
};
struct node *p,*q;
p=malloc(sizeof(struct node));
q=malloc(sizeof(struct node));
printf("%d%d",sizeof(p),sizeof(q));
}
Output: 22

Share |

Labels:

0 comments:

Post a Comment