Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Consider the following statements. What is the output if the user enters the

ID: 3688146 • Letter: 1

Question

1. Consider the following statements.

What is the output if the user enters the underlined string:

100catsin1 2hats? (3 pts)

int a, b;

char str = [20];

scanf(“%d%s%d”, &a, str, &b);

printf(“a = %d, b = %d, str = %s ”, a, b, str);

2. Consider the following array declarations.(4 pts)

char x[25], y[25], z[25];

Add statements to: -

Read two strings from the user into x and y. -

Copy the one that comes first in lexicographical order into z.

-Print z to the standard output.

3. What is the value of str1 after each statement (lines 2-5) (2pts):

char str1[100];

strcpy(str1, “The Force Awakens”);

str1[3] = ‘’;

strcpy(str1 + 3, “!”);

strcat(str1, “Again”);

4. Consider the following string, write a statement to print the substring starting at never : (1 pt)

char markTwainQ[200] = “I have never let my schooling interfere with my education” ;

Explanation / Answer

1) a= garbage value (-29254- in 64 bit system) b= 657 ( Converted in ASCII = 1hat) str=catsin

2)

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

using the above libraries you can access a predefined method called

int compare (const void *a, const void * b)

and to swap we can use swap method using temp t.

void swap (char* a, char* b)

{

    char t = *a;

    *a = *b;

    *b = t;

}

3)

"The Force Awakens" get copied to str1

str1[3]='o'; makes it to null string

strcpy(str1+3, '!'); copies 1st 3 char values to the string i.e. "The" and '!'

strcat("Again"); concatinates strings "The!" and "Again"

Final Output= The!Again

4)