

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This lab practice for computer fundamentals course focuses on writing two rapper functions in c for malloc and free to check successful memory allocation and returning memory, and explaining the functionality of given code examples.
Typology: Exercises
1 / 3
This page cannot be seen from the preview
Don't miss anything!
1 // Ex. 8.21: ex08_21.cpp 2 // What does this program do? 3 #include <stdio.h> 4 #include <stdlib.h> 5 6 7 8 void mystery1( char *, const char * ); // prototype 9 10 int main() 11 { 12 char *string1; 13 char *string2; 14 15 printf("Enter two strings: "); 16 scanf("%d,%d",&string1,&string2); 17 mystery1 (string1, string2); 18 printf("%s",string1); 19 return 0; // indicates successful termination 20 } // end main 21
22 // What does this function do? 23 void mystery1( char *s1, const char *s2 ) 24 { 25 while ( *s1 != '\0' ) 26 ++s1; 27 28 for ( ; *s1 = *s2; s1++, s2++ ); // empty statement 30 } // end function mystery 1 // Ex. 8.21: ex08_29.cpp 2 // What does this program do? 3 #include <stdio.h> 4 #include <stdlib.h> 5 6 7 8 int mystery3( const char *, const char * ); // prototype 9 10 int main() 11 { 12 char *string1, *string2; 13 14 printf("Enter two strings: "); 15 scanf("%d,%d",&string1,&string2); 16 printf( "The result is %d\n",mystery3( string1, string2 ); 17 return 0; // indicates successful termination 18 } // end main 19 20 // What does this function do? 21 int mystery3( const char *s1, const char *s2 ) 22 { 23 for ( ; *s1 != '\0' && *s2 != '\0'; s1++, s2++ ) 24 25 if ( *s1 != *s2 ) 26 return 0; 27 28 return 1; 29 } // end function mystery