Suppose you have strings char S1 rodent char S2 dog char S

Suppose you have strings: char S1[] = {\"rodent\"}; char S2[] = {\"dog\"}; char S3[20]; What is the value of S2[1]? X = strlen (S1); What value does X receive? Z = strepm (S1, S2); What is the value of z? After strcpy (S3, S1) what is in S3? For string S5 of unknown length and value write C++ to count the number of questions marks in string S5.

Solution

c) z = strcmp (S1, S2) is 14

the first character that does not match has a greater value in s1 than in s2

here

char S1[ ] = {“rodent”};

char S2[ ] = {“dog”}; s1[0] is r and s2[0] is d

it return difference between r and d in trems of ascii

answer is 14

e)

Here is code:

int count = 0;
char S5[ ] = {\"r?o?dsam?ple?nt\"};
for(int i = 0; i<strlen(S5);i++)
{
if(S5[i] == \'?\')
count++;
}

Sample code to test:

#include <iostream>
#include <string.h>
using namespace std;

int main()
{
int count = 0;
char S5[ ] = {\"r?o?dsam?ple?nt\"};
// loops from 0 to length of S5
for(int i = 0; i<strlen(S5);i++)
{
if(S5[i] == \'?\') // if it matches with ?
count++;
}
cout <<\"The number of times ? occurs is \" << count << endl;

return 0;
}

Output:

The number of times ? occurs is 4

Rest of answer are correct

>0

the first character that does not match has a greater value in s1 than in s2

 Suppose you have strings: char S1[] = {\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site