Consider thefollowing function definitions: void fun1(int [], int); //function p
ID: 3613284 • Letter: C
Question
Consider thefollowing function definitions:
void fun1(int [], int); //function prototype
void fun2(int *, int &); // function prototype
void fun1 (int x[], inty)
{
for (int i = 0; i < y; i++)
x[i] = i;
}
void fun2 (int *x,int& y)
{
*x = *x * *x *y;
}
Also suppose that an arraynamed a is declared as
int a[10], and integer b is declared and initialized as int
b=10.
Which of the followingfunction calls will cause either syntax,
run-time and/or logic errors?
(NOTE: lines with fun1 orfun2 calls are numbered on the left
most column so that they can be referenced in the possible
answers below. Do not consider them as part of a source file
that is compiled.)
int main()
{
int a [10];
int b=10;
a syntax, runtime and/orlogic error.
c) 2, 3, 4, 5, 7, 8, and 10 will cause either a
syntax, runtime and/or logic error.
d) All lines will cause either a syntax, runtime
and/or logic error.
e) None of the lines will cause an error.
Explanation / Answer
void fun1(int [], int); //function prototype
void fun2(int *, int &); // function prototype
void fun1 (int x[], inty)
{
for (int i = 0; i < y; i++)
x[i] = i;
}
void fun2 (int *x,int& y)
{
*x = *x * *x *y;
}
Also suppose that an arraynamed a is declared as
int a[10], and integer b is declared and initialized as int
b=10.
Which of the followingfunction calls will cause either syntax,
run-time and/or logic errors?
(NOTE: lines with fun1 orfun2 calls are numbered on the left
most column so that they can be referenced in the possible
answers below. Do not consider them as part of a source file
that is compiled.)
int main()
{
int a [10];
int b=10;
a syntax, runtime and/orlogic error.
c) 2, 3, 4, 5, 7, 8, and 10 will cause either a
syntax, runtime and/or logic error.
d) All lines will cause either a syntax, runtime
and/or logic error.
e) None of the lines will cause an error.
none of theseare correct - the correct answer is
Lines 2,3, 5, 7, 8, and 10 will cause either a
syntax, runtime and/or logic error.