Quiz-Nov

.pdf

School

Humber College *

*We aren’t endorsed by this school

Course

IPC144

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

10

Uploaded by DeaconStarGerbil23

Report
1- What will be the output of the following code? // C Program to illustrate the strcat function #include <stdio.h> int main() { char dest[50] = "This is an" ; char src[50] = " example" ; printf ( "dest Before: %s\n" , dest); // concatenating src at the end of dest strcat (dest, src); printf ( "dest After: %s" , dest); return 0; }
2- What will be the output of the following code? / C program to demonstrate the strlen() function #include <stdio.h> #include <string.h> int main() { // Declare and initialize a character array 'str' with // the string "GeeksforGeeks" char str[] = "GeeksforGeeks" ; // Calculate the length of the string using the strlen() // function and store it in the variable 'length' size_t length = strlen (str); // Print the length of the string printf ( "String: %s\n" , str); printf ( "Length: %zu\n" , length); return 0; } 3- What will be the output of the following code? int main() { // Define a string 'str1' and initialize it with "Geeks" char str1[] = "Geeks" ; // Define a string 'str2' and initialize it with "For" char str2[] = "For" ; // Define a string 'str3' and initialize it with "Geeks" char str3[] = "Geeks" ; // Compare 'str1' and 'str2' using strcmp() function and // store the result in 'result1' int result1 = strcmp (str1, str2); // Compare 'str2' and 'str3' using strcmp() function and // store the result in 'result2' int result2 = strcmp (str2, str3); // Compare 'str1' and 'str1' using strcmp() function and // store the result in 'result3' int result3 = strcmp (str1, str1);
// Print the result of the comparison between 'str1' and // 'str2' printf ( "Comparison of str1 and str2: %d\n" , result1); // Print the result of the comparison between 'str2' and // 'str3' printf ( "Comparison of str2 and str3: %d\n" , result2); // Print the result of the comparison between 'str1' and // 'str1' printf ( "Comparison of str1 and str1: %d\n" , result3); return 0; }
4- What will be the output of the following code? // C program to illustrate the use of strcpy() #include <stdio.h> #include <string.h> int main() { // defining strings char source[] = "GeeksforGeeks" ; char dest[20]; // Copying the source string to dest strcpy (dest, source); // printing result printf ( "Source: %s\n" , source); printf ( "Destination: %s\n" , dest); return 0; }
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help