2. Consider the following strings variable definitions. char sl\"love\"; char s2
ID: 3742641 • Letter: 2
Question
2. Consider the following strings variable definitions. char sl"love"; char s2"to program!"; char s3[] = "I am, therefore char s4 [80]; "; strcpy (s4, "CSE 5A!"); What gets printed? printf( "%c", s4 [2] ); printf( "%d", strlen( s4 ) printf( "%d", sizeof( s1 ) ); ); Fill in the blanks to complete the following tasks: /*Change 'A' in string s4 to 'a' without explicitly assigning the value 'a'*/ ; /* Cannot have 'a here! For example, you CANNOT do something like: blahblahblah-'a' /Change the ',' in string s3 to '!'*/ /*The resulting output is "I love CSE 5A!" in a single printf ) statement. */ printf( "%Explanation / Answer
Print statement values are :
1. printf("%c", s4[2]); E
2. printf("%d", strlen(s4)); 7
3. printf("%c", sizeof(s1)); 5
4. s4[5] = tolower(s4[5]);
5. s3[4] = '!';
6. printf("%c %s %s", s3[0], s1, s4);
Please find complete code in bold -
#include <string.h>
#include <iostream>
#include <cstring>
#include <ctype.h>
using namespace std;
int main()
{
char s1[] = "love";
char s2[] = "to program!";
char s3[] = "I am, therefore...";
char s4[80];
strcpy(s4, "CSE 5A!");
printf("%c", s4[2]);
printf(" ");
printf("%d", strlen(s4));
printf(" ");
printf("%d", sizeof(s1));
printf(" ");
s4[5] = tolower(s4[5]);
s3[4] = '!';
printf("%c %s %s", s3[0], s1, s4);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.