Question 6 (a) The C function int strlen (char stringl]); returns the length of
ID: 3909738 • Letter: Q
Question
Question 6 (a) The C function int strlen (char stringl]); returns the length of a null-terminated string. i. What is a null-terminated string? [2 marks] ii. Write an implementation of the strlen function. [5 marks)] (b) Write a C function with signature void multiScalar(int AL 1 [5], int rows, int factor); that multiplies a rows × 5 matrix A by a scalar factor (c) Explain what void means in the C function signature (d) main is making 3 calls to the function multiScalar as shown below (6 marks] [2 marks] int main ) int int int factor [3] [5]- 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; new [4] [5]; x=2; multiScalar(factor, 3, x); multiscalar(neu, 4, 5); multiScalar(factor, 4, 4); For each call, will that line compile or generate an error? If it compiles, briefly explain the outcome of that call [9 marks] [Total for Question 6: 24 marks]Explanation / Answer
Qa)
The null terminated string is a character array which ends with the character ''
The implementation will be
int strlen(char arr[])
{
int i=0;
while(arr[i++]);
return i;
}
Q2
The code will be
void multiScalar(int arr[][5],int rows,int factor)
{
int i,j;
for(i=0;i<rows;i++)
for(j=0;j<5;j++)
arr[i][j]*=factor;
}
Q3
void means that the function is not returning anything
Q4
It will not generate any error and will multiply the array with the third value provided
Do give a thumbs up
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.