Question

Programming In C A) What will print after the following statements execute? char s1[50] = "jack";...

Programming In C

A)

What will print after the following statements execute?

char s1[50] = "jack";
char s2[50] = "jill";
char s3[50];
printf("%s", strcat(strcat(strcpy(s3, s1), " and "), s2));

B) What will print after the following statements execute? char s1[50] = "jack"; char s2[50] = "jill"; char s3[50]; printf("%u", strlen(s3));

0 0
Add a comment Improve this question Transcribed image text
Answer #1

)
char s1[50] = "jack";

char s2[50] = "jill";

char s3[50];

printf("%s", strcat(strcat(strcpy(s3, s1), " and "), s2));

After the first 3 statement three memory locations of 50*sizeof(int) space each is created namely s1,s2 and s3
Out of these 3 s1 and s2 are provided with string values "jack" and "jill" respectively
Now when the fourth statement is executed it begins by copying the value of s1 in s3
then the function stcat is called which concatenates it with the word "and" then lastly
s2 is concatenated at the end of the string thereby giving us the final output as:

jack and jill

B)
char s1[50] = "jack";
char s2[50] = "jill";
char s3[50];
printf("%u", strlen(s3));

Now the first 3 statements in B) remains the same as A)
now this time strlen function is called which is used to calculate the length of the string provided
which is s3
now %u is used which returns the value in unsigned integer
so the output printed will be:
1

Reason for the above answer is as there is no value in the character array s3 and lenght is returned in positive value so "1" is returned.

if this answer helps you please give thumbs up

Add a comment
Know the answer?
Add Answer to:
Programming In C A) What will print after the following statements execute? char s1[50] = "jack";...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • int main(void) { char s1[50]="jack", s2[50]="jill", s3[50]; printf("%s\n",strcat(strcat(strcpy(s3,s2)," and "),s2)); printf("%i",strlen(s1)+strlen(s2)); } Output?

    int main(void) { char s1[50]="jack", s2[50]="jill", s3[50]; printf("%s\n",strcat(strcat(strcpy(s3,s2)," and "),s2)); printf("%i",strlen(s1)+strlen(s2)); } Output?

  • What will the value of the string s1 after the following statements have been executed? strcpy(s1,...

    What will the value of the string s1 after the following statements have been executed? strcpy(s1, "computer"); strcpy(s2, "science"); if(strcmp(s1, s2) < 0){     strcat(s1, s2); } else{     strcat(s2, s1); } s1[strlen(s1) - 6] = '\0'; I know the answer is "Computers" but why? Can someone explain to me how to approach this problem?

  • Problem Consider three processes A, B, and C which have statements S1, S2 and 53 respectively....

    Problem Consider three processes A, B, and C which have statements S1, S2 and 53 respectively. These statements should execute in a particular fashion. S3 should be executed only after executing S1 and S2. Statements S1 and 52 can be executed in any order. Implement the above using binary semaphore variables X1 and X2 which are initially set to zero. O A: S1; signal (x1); B: S2; signal (X2); C: wait(x1); wait (X2); S3;

  • C programming 1 String Merging Write a program that reads two strings s1 and s2 from...

    C programming 1 String Merging Write a program that reads two strings s1 and s2 from the keyboard and merges them to a string s3. Strings s1 and s2 are statically allocated whereas s3 is dynamically allocated to fit exactly s1 and s2. The two original strings are no longer than 100 characters long. Use the following function to merge the two strings. char *stringMerge(char s1[], char s2 []); Example: Enter the first string: Hello world Enter the first string:...

  • Question 1 Which pre-written C function can be used to determine if two strings are the...

    Question 1 Which pre-written C function can be used to determine if two strings are the same? A) equals B) strcmp C) strlen D) strcpy E) None of the Above Question 2 The function below is most like which existing string function? int f(char a[ ]) {                int count = 0;                while (a[count] != ‘\0’)                               count++;                return count; } A) strcat B) strcmp C) strcpy D) strlen E) None of the Above Question 3 The function...

  • 1. Given the string variables pres, first, and last as defined in Example 9.2 provided on...

    1. Given the string variables pres, first, and last as defined in Example 9.2 provided on page 459 of your textbook, Problem Solving and Program Design in C, show what would be displayed by this code fragment. (If you do not know, you can always place this code into the proper C coding structure and compile and execute.) Make certain your call includes <stdio.h> and <string.h> and declare your variables if you are going to compile. (Hint:Refer to the text...

  • JAVA PROGRAMMING I want to make sure I have learned the compareto statements correct and other...

    JAVA PROGRAMMING I want to make sure I have learned the compareto statements correct and other things. This was on my lecture slide today and I don't understand the compare to regarding how they get values for the strings. Please answer the following. Suppose that s1, s2, and s3 are three strings, given as follows String s1 = "Welcome to Java". String s2 = "Programming is fun". String s3- "Welcome to Java" hat are the results of the following expressions?...

  • IN C-PROGRAMMING: What is Structured Programming; what is machine and assembly coding; what is pseudo coding?...

    IN C-PROGRAMMING: What is Structured Programming; what is machine and assembly coding; what is pseudo coding? What do the following do:   compiler, preprocessor, return 0, { }? Describe data types and what distinguishes each;  how would one combine data types? Explain functions and what are they for? Explain:  scanf (gets, fgets, getchar, fgetchar), printf( puts, fputs, putchar, fpetchar) What do the following mean:   strlen, strcmp, strcat, strcpy? What does fopen and fclose mean? Explain the difference between stdin and file. What if your file...

  • C programming Question1 (a) Write a C program that will print out all command line arguments,...

    C programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...

  • Please answer problem #5 thank you str.c #include "str.h" #include <stdio.h> int str_len(...

    Please answer problem #5 thank you str.c #include "str.h" #include <stdio.h> int str_len(char *s) {    /* this is here so code compiles */ return 0; } /* array version */ /* concantenate t to the end of s; s must be big enough */ void str_cat(char s[], char t[]) {    int i, j;    i = j = 0;    while (s[i] != '\0')    /* find end of s */        i++;    while ((s[i++] = t[j++]) != '\0') /* copy t */        ;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT