array variable not working, x[0] is getting over written with value of xx[1]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 9916340778
    New Member
    • Sep 2014
    • 1

    #1

    array variable not working, x[0] is getting over written with value of xx[1]

    #include<stdio. h>
    #include<iostre am>
    #include<graphi cs.h>
    #include<conio. h>
    #include<math.h >
    using namespace std;

    using namespace std;
    main()
    {
    int x,y,leftbit[]={0,0},rightbit[]={0,0},topbit[]={0,0},bottombi t[]={0,0},flag=0,i ,xmin,xmax,ymin ,ymax;
    int xx[1],yy[1],xb[1],xt[1],yl[1],yr[1],m;
    int a[3],o[3];

    cout<<"Enter the co-ordinates of the line ";

    cout<<"\nPoint A :- ";
    cin>>xx[0];
    cin>>yy[0];

    cout<<"\nPoint B :- ";
    cin>>xx[1];//xx[0] is getting over written at xx[1]
    cin>>yy[1];

    initwindow(700, 700);

    line(xx[0],yy[0],xx[1],yy[1]);

    cout<<xx[0]<<" "<<yy[0]<<"\n";
    cout<<xx[1]<<" "<<yy[1];
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    xx is an array of one element: int xx[1].

    That means xx[0] is the only element yet you cin >> xx[1]. There is no xx[1] so you corrupt your local stack frame.

    Comment

    Working...