Home » Ask & Discuss » Board Exams - CBSE, ICSE, State Boards » Computer Science « Back to Discussion
Computer Science
give output ,take rates!!!!!!!
None
1) find output:
void main()
{
struct
{int x,y;
}*p,sg[4]={{9,8},{7,6},{5,4},{3,2}};
p=&sg[0];
for(int i=0;i<4;i++,p++)
cout<<(p+i)->x<<"\t"<<(p+i)->y<<endl;
}
is the output????: 7 6
5 4
3 2
9 8
2) whatis d difference between a[x++] and a[x]++,xplain!!!!!!!
3) find output:
void main()
{
struct point
{ int x,y;
}ob[]={ {1,7},{15,25},{35,45},{55,65}};
point *a;
a=ob;
a++;
a->x++;
a++;
a->y++;
cout<<ob->x<<" "<<a-y<<endl;
cout<<ob->y<<" "<<a->y<<endl;
}
plz reply soon
rates assured!!!!!!!!!!!!!!!!!!
Comments (5)
RyuAmakusa
Blazing goIITian

Joined: 21 Mar 2008
Posts: 776
30 Mar 2008 16:38:07 IST
Like
1 people liked this
9 8
5 4
then some crap will be printed because the pointer goes beyond the scope of the array.
Reply
31 Mar 2008 19:18:26 IST
Like
1 people liked this
ob[]={ {1,7},{15,25},{35,45},{55,65}};
point *a;
a=ob; // now a will contain the adress of ob[0].
a++; // now a will contain the adress of ob[1].
a->x++; // now ob[1]->x is incrimented ie.15 becomes 16
a++; // now a will contain the adress of ob[2]. ----------(1)
a->y++; // now ob[2]->y is incrimented ie.45 becomes 46
cout<<ob->x<<" "<<a-y<<endl;//ob contains adress of ob[0] so ob->x is 1
and a->y is 46 from (1)
cout<<ob->y<<" "<<a->y<<endl; //now ob->y is 7 and a->y is 46 from (1)
so it is
1 46
7 46
I hope it's clear If not ask;










