Question

What is the value of t1 after execution of these statements if the value of t2 is as follows: chart1[6]; chart2 [ ]=Happy St
Which one of the following statements would call function somefun only if the string values of character arrays a and b were
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1: Happy

Solution explanation with code screenshot;-

Program code:-

#include <stdio.h>
#include <string.h>
int main()
{
//String of size 6 is defined
char t1[6];
char t2[]= "Happy Studying";
  
/*string t2 is being copied to string t1
only first 5 characters is copied to string t1.
*/
strncpy(t1,t2,5);
// delimiter '\0' assinged at t1[5] marking send of the srting
t1[5] = '\0';
  
printf("Value of t1 is: ");
for(int i=0; t1[i]!= '\0'; i++ )
printf("%c", t1[i]);
  
return 0 ;
}
Screenshot

main.c #include <stdio.h> 2 #include <string.h> 3 int main() 4-{ //String of size 6 is defined char t1[6]; char t2[]= Happy

Solution 2:- C if ( strcmp(a, b) == 0 ) somefun();

Explanation

somefun() will be called when the if clause will be true and this if clause will be true if variable a and b hold dame character.

Add a comment
Know the answer?
Add Answer to:
What is the value of t1 after execution of these statements if the value of t2...
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
  • 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...

  • computer science questions 13. What is the value of the expression that follows? strcmp ("dog", "dogs");...

    computer science questions 13. What is the value of the expression that follows? strcmp ("dog", "dogs"); 0 nosodo none of the above 14. What is the value of the expression that follows? strcmp ("dog", "Dog"); a. -1 e. '10' none of the above 15. Which character is used to left justify the string argument in printf? 0 \left 16. To test whether a character is one of '0', '1', '2', '3', '4', '5', '6', '7', '8', or '9', use the...

  • 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?

  • # After the if statement that follows is executed, what will the value of $discount_amount be?...

    # After the if statement that follows is executed, what will the value of $discount_amount be? $discount_amount; $order_total = 200; if ($order_total > 200) { $discount_amount = $order_total * .3; } else if ($order_total > 100) { $discount_amount = $order_total * .2; } else { $discount_amount = $order_total * .1; }         2         20         40         60 # To open a file in PHP, you use the _________ function.         fopen()        ...

  • C language not C++ 1. Write the statements to do the following: (2 pts) a. Define...

    C language not C++ 1. Write the statements to do the following: (2 pts) a. Define a struct with member variables width, height, topleft x, topleft y all floats). Use a tag to call it Rectangle. b. Declare a variable struct type Rectangle 2. Consider the following variables: struct int x; float y; char zi var1; union nt x; float y; char[20] z;) var2 f float and int are stored using 4 bytes each, what is the size (in bytes)...

  • A method called linearSearch(), which takes as parameters an array of int followed by three values...

    A method called linearSearch(), which takes as parameters an array of int followed by three values of type int, and returns a value of type int. The first int parameter represents a key, the second int parameter represents a starting position, and the third int parameter represents an end position. If the key occurs in the array between the start position (inclusive) and the end position (exclusive), the method returns the position of the first occurrence of the key in...

  • in java no mathcall please ennas are out of date.Please sign was wkollieemail.cpeedu so we can...

    in java no mathcall please ennas are out of date.Please sign was wkollieemail.cpeedu so we can verily your subscription Sign In ASSIGNMENT Unit 9 Methods, Arrays, and the Java Standard Class Library Reimplementing the Arrays class (60 points) The Arrays class, which is also part of the Java standard class library, provides various class methods that perform common tasks on arrays, such as searching and sorting. Write a public class called MyArrays, which provides some of the functionality which is...

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

  • Write and test a function toDecimal() that converts a roman number such as MCMLXXVII to its...

    Write and test a function toDecimal() that converts a roman number such as MCMLXXVII to its decimal number representation. Write a main program to test the function. Your function should have two arguments - the roman number as a string, and an error processing function. Write a helper function that will return the numeric value of each of the letters used in roman numbers. Then convert the string argument as follows look at the first two characters. If the first...

  • Assignment Draw a flowchart, using Microsoft Visio or LucidChart, to document the logic required to complete...

    Assignment Draw a flowchart, using Microsoft Visio or LucidChart, to document the logic required to complete this program Save the flowchart as a PDF file Develop a C++ program, following the logic in your flowchart, to convert a series of whole number decimal values to their Roman equivalent. Develop a function that will accept a whole number value in the range 1-9999 and return a string containing the long-form Roman Numeral equivalent of the input value, consisting only of upper-case...

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