Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in C only
Search
Advanced Search
Forums
BYTES
Product Launch
Updates
Developer Toolkit
Today's Posts
Member List
Calendar
Home
Forum
Topic
C
general protection exception is written when execute my program why is it happen.
Collapse
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
naobi
New Member
Join Date:
May 2012
Posts:
1
#1
general protection exception is written when execute my program why is it happen.
May 8 '12, 06:50 AM
my code in c++ is
Code:
#include<iostream.h> main() {int a[10],x[5]; a[-7]=15; x[5]=20; cout<<x[-5]; }
Last edited by
Meetee
;
May 8 '12, 06:57 AM
.
Reason:
code tags added
Banfa
Recognized Expert
Expert
Join Date:
Feb 2006
Posts:
9067
#2
May 8 '12, 11:49 AM
because -7 and -5 are outside the bounds of the array and result in undefined behaviour.
Most likely when you access with these indices you hit a memory address that is not current valid for the program and hence the exception.
Comment
Post
Cancel
donbock
Recognized Expert
Top Contributor
Join Date:
Mar 2008
Posts:
2427
#3
May 8 '12, 12:00 PM
What do you want to happen when you use those negative indices?
Comment
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment