What does this program do? /* ex07_21.c */ /* What does this program do? */ #inc
ID: 3622184 • Letter: W
Question
What does this program do?/* ex07_21.c */
/* What does this program do? */
#include <stdio.h>
void mystery1( char *s1, const char *s2 ); /* prototype */
int main( void )
{
char string1[ 80 ]; /* create char array */
char string2[ 80 ]; /* create char array */
printf( "Enter two strings: " );
scanf( "%s%s" , string1, string2 );
mystery1( string1, string2 );
printf("%s", string1 );
return 0; /* indicates successful termination */
} /* end main */
/* What does this function do? */
void mystery1( char *s1, const char *s2 )
{
while ( *s1 != '' )
{
s1++;
} /* end while */
for ( ; *s1 = *s2; s1++, s2++ )
{
; /* empty statement */
} /* end for */
} /* end function mystery1 */
Explanation / Answer
Dear,
Given code the following are the sequence opartions
1) first inputs two strings
2) function call mystery with these two string passed by reference
3 ) print first string
The execution of main code concatenates both strings and stores in string1
void mystery1( char *s1, const char *s2 )
{
while ( *s1 != '' )
{
s1++;
} /* end while */
/*This loop repeats untill end of first string and pointer finally points to null
/* This for loop repats untill end of second string and assigns each character to first string
for ( ; *s1 = *s2; s1++, s2++ )
{
; /* empty statement */
} /* end for */
} /* end function mystery1 */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.