Skip to content
EMPS intranet

Back to top
Hi!   Hi!           Start main()

Try stepping through the code


  Value and type of last evaluated expression: Address of array element: Address of array elementx:  (none)

Your browser does not support the canvas element which will make some the features unavailable.

If you are using Internet Explorer within the University of Exeter try going to the Settings menu (probably the gear shape at the top right of this page), selecting "Compatibility View settings", unchecking "Display intranet sites in Compatibility View" and reloading this page.

Code

 Header...
#define LENGTH 26 struct mystruct { float val; char *str; int length; };
int main(){
  ...
» struct mystruct struct1, struct2; » char stringbuffer[LENGTH]; » struct1.val=3.14259; » struct1.length=LENGTH; » struct1.str=stringbuffer; » strncpy(struct1.str, "This is the value of Pi!", LENGTH); » struct2=struct1; » »» » strncpy(struct1.str, "Oops! No it isn't!", struct1.length); » printf("%s\n%s\n", struct2.str, struct1.str);
}
Memory

main()

128
129
130
131
132
133
134
135
struct1.val = 3.99837975e-34
struct1.str = -4286648983
136
137
138
139
140
141
142
143
struct1.length = -8318092
struct2.val = -4.37194123e+33
144
145
146
147
148
149
150
151
struct2.str = -4286648983
struct2.length = 200
152
153
154
155
156
157
158
159
?
?
stringbuffer = '\ ' '\0' ' ' 'q' ' ' ' '
160
161
162
163
164
165
166
167
'\0' '\0' '\0' ' ' ' ' '\ ' '8' ' '
168
169
170
171
172
173
174
175
' ' ' ' 't' ' ' ' ' ' ' ' ' '\0'
176
177
178
179
'\0' '\0'
?
?

NB: the actual memory address of each variable is the
address shown plus 4286648984 (0xFF811298).

Show Advanced options

.
Show output (Before looking at the output, work out what you think it put should be and see if you are right.)

Output

Oops! No it isn't!
Oops! No it isn't!
                                                                                                                                                                                                                                                                       

Validate   Link-check © Copyright & disclaimer Share
Back to top