Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Which statements about the following piece of code are TRUE? ( Check all that apply ) char * repeated ( char * original, int n

Which statements about the following piece of code are TRUE? (Check all that apply)
char * repeated (char* original, int n){
int i, length = strlen(original);
char* newString = malloc (sizeof(char)* length * n +1);
char * helper = newString;
for (i =0; i < n; i++){
strcpy(helper, original);
helper = helper + length;
{
return newString;
}
- Each time helper is incremented by the length of the incoming string, its value jumps to the NULL character location in the newly built string
- helper is a pointer that initially points to the beginning of the string that is passed to function repeated
- strlen function returns the number of characters in the string passed to repeated, including the NULL character
- In order to perform memory clean-up, the free statement should be placed inside the function that calls function repeated but only after the resulting value is no longer needed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions