Question

Suppose that p has been declared as follows Char *p= “abc”; Which of the following functions...

Suppose that p has been declared as follows

Char *p= “abc”;

Which of the following functions calls are legal? Show the output produced by each legal call and explain why the others are illegal

Put char (p);

Putchar(*p);

Puts(p);

Puts(*p);

Suppose that str is an array of characters. Which of the following statements is not equivalent to the other three?

*str = 0;

Str[0] = ‘\0’;

Strcpy( str, “”);

Strcat(str. “”);

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

ANSWER:-

To find which of the following functions calls are legal:-

i.)putchar(p); -- illegal call. Because the function expects a character not an integer address.

ii.)putchar(*p); // legal call will print a.

iii.)puts(p) ; legal call will print whole string abc.

iv.)puts(*p) –illegal call as function expects a string not a character.

To find which of the following statements is not equivalent to the other three:-

Given that str is an array of character.

i)*str = 0;

ii ) Str[0] = ‘\0’;

iii) Strcpy( str, “”);

iv) Strcat(str. “”);

Hence, observing the four options option (iv) Strcat(str. “”); is correct one. i.e., not equivalent to the other three.

Here, options (i) , (ii) and (iii) are equivalent in terms of what they final result i.e., an empty string.

*str = 0; - This makes the pointer str (as name of any array used as a pointer to that array) store an integer value in first character of array which is not possible. So, it behaves like an empty string.

str[0] = '\0'; - It turns the first element of the character array into null character thus ending the string there itself in the beginning making it an empty string.

strcpy(str, ""); - It overwrites the existing contents of string with an empty string (containing only '\0' ). So, it becomes an empty string.

strcat(str, ""); - It is a empty string is appended after that the original string.

Thus leaving the original string in str and not an empty string. So,it is not equivalent to other three.

Add a comment
Know the answer?
Add Answer to:
Suppose that p has been declared as follows Char *p= “abc”; Which of the following functions...
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
  • I'm getting errors that i can't figure out. I need help fixing them. particularly focus on...

    I'm getting errors that i can't figure out. I need help fixing them. particularly focus on the errors they are highlighted in bold on the list code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <ctype.h> #include "stack.h" #include "booleanEvaluation.h" #include "booleanWithError.h" /* evaluatePostfix * input: a postfix expression * output: T, F, or E * * Uses a stack to evaluates the postfix expression and returns the result as a string where "T" denotes true and "F" denotes...

  • Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You...

    Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You will place all of your function prototypes in a header file named string utils.h and all of your function definitions in a source file named string utils.c. You should implement your own main test driver program to test your functions, but you need not hand it in. a. void addChar(char *str, char c, int n) - this function should add a char c at...

  • In C# (sharp) Assuming a string variable named movie Title has already been declared, which one...

    In C# (sharp) Assuming a string variable named movie Title has already been declared, which one of the following statements combines the strings "Hidden" and "Figures" and then assigns the resulting string to the variable? 1. movieTitle="Hidden" + "Figures"; 2. "Hidden" +"Figures" - moveTitle; 3. movie Title("Hidden" +"Figures"); 4. movie title="Hidden" & "Figures": Look at the following code: int distance; // Declare distance as an int double half://Declare half as a double distance = 35; // Assign 35 to distance...

  • This program should be run on Visual Studio. Please use printf and scanf as input and output. Tha...

    This program should be run on Visual Studio. Please use printf and scanf as input and output. Thank you 6.12 Lab Exercise Ch.6b: C-string functions Create and debug this program in Visual Studio. Name your code Source.c and upload for testing by zyLabs You will write 2 functions which resemble functions in the cstring library. But they will be your own versions 1. int cstrcat(char dstDchar src) which concatenates the char array srcl to char array dstD, and returns the...

  • 5. Suppose that you sold an American put option P on the underlying stock ABC. You...

    5. Suppose that you sold an American put option P on the underlying stock ABC. You calculated the delta and gamma of the put option and found Ap = -0.4 and Ip= 0.3. Suppose you want a position which is both delta and gamma neutral. Determine the hedge in the following two cases: (a) Use the underlying stock itself and a call option C on the stock (with different strike and maturity as the put), with Ac 0.25 and Io...

  • pUI) FOU are to write a function which has a prototype: void count (char sl, int *pUpper, "pLower, "poigit, pother) s [ is a character string which may be of any length. Other arguments a...

    pUI) FOU are to write a function which has a prototype: void count (char sl, int *pUpper, "pLower, "poigit, pother) s [ is a character string which may be of any length. Other arguments are address of where the number of upper, lower, digits, and other characters in the string should be placed. For example (this is only an example) the code (put into a properly written program): char all "12145-9ABD, 3f0 :bbB2" char bll "148x3!!" char c[] = {...

  • Suppose that the demand and supply functions are P=10-Q and P=Q respectively. Which of the following...

    Suppose that the demand and supply functions are P=10-Q and P=Q respectively. Which of the following statements are correct for the value of consumer and producer surplus in the equilibrium? Select one or more: a. The value of producer surplus is 25. b. The value of consumer surplus is 15. c. The value of consumer surplus is 12.5. d. The value of producer surplus is 15. e. The value of consumer surplus is 25. f. The value of producer surplus...

  • 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 */        ;...

  • Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string"...

    Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string" is a sequence of characters. In the C language anything within double quotes is a "string constant" so you have been seeing strings all semester. But we can also have string variables. In the C language these are implemented as an array of char, e.g. char name (10]: In order to make these variables easier to work with, it has been universally agreed that...

  • Multiple Choice Multiple Choice Section 4.1 Pointers and Dynamic Memory Consider the following statements: int *p;...

    Multiple Choice Multiple Choice Section 4.1 Pointers and Dynamic Memory Consider the following statements: int *p; int i; int k; i = 42; k = i; p = &i; After these statements, which of the following statements will change the value of i to 75? A. k = 75; B. *k = 75; C. p = 75; D. *p = 75; E. Two or more of the answers will change i to 75. Consider the following statements: int i =...

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