What happens if you run a Matlab program that indexes values

What happens if you run a Matlab program that indexes values beyond the end of an array? What happens if you index beyond the end of an array in a C-program? Briefly explain the reasons for each of these behaviors.

Solution

If you run a MATLAB program that indexes values beyond the end of the array then it will produce a runtime error message.

Example :

clc;
close all;
clear all;
A = magic(4);
A(4,2)%no error
A(5,2)% error : Index exceeds matrix dimensions.

In C-program, indexing beyond the end of an array will produce unpredictable results.

If you write beyond the end of a C array you will overwrite other data, or maybe even the stack

Example :

It will print garbage after the end of the word string.

 What happens if you run a Matlab program that indexes values beyond the end of an array? What happens if you index beyond the end of an array in a C-program? B

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site