C Language - Chapter 8

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which specifier is used to print a ctring or character array in C printf function? %c %cs %w %s

%s

What is the value of strcmp("abc", "aefg")? -1 1 0 Cannot determine.

-1

What's the output of the following code? char name1[10] = "joanna"; char name2[10] = "john"; printf("%d", strcmp(name1, name2)); -1 7 -7 0

-7

What's the output of the following code? #include <stdio.h> #include <string.h> int main () { char str[10] = "C Program"; memset(str,'#',4); printf("%s", str); }

CCCCogram

What's the output of the following code? char name[10] = "joanna"; printf("%lu", strlen(name)); 6 10 9 7

6

Given the following input John Smith what's the output of the following program? #include <stdio.h> int main() { char name1[4]; char name2[4]; // use fgets to read in name and address scanf("%s", name1); scanf("%s", name2); printf("%s %s", name1, name2); } John Smit Cannot determine as there is an overflow. Joh n John Smit

Cannot determine as there is an overflow.

Which of the following is not needed when we handle a full input buffer? Deallocate the old character array. Allocated a new larger character array. Copy the content of the old character array to the new character array. Create a buffer that is the same size as the old buffer and append it to the old buffer.

Create a buffer that is the same size as the old buffer and append it to the old buffer.

Analyze the following code. int main() { char str[]= "CST"; printf("%s",str); return 0;} which of the following best describes the above code? It displays CST\0 It displays CST It displays C, S, T There is a compile error.

It displays CST

Given two char arrays s1 and s2, the size of s1 and s2 are m1m1 and m2m2, and m1≤m2m1≤m2 respectively, which of the following statement is true? It is always safe to use strcmp(s1, s2). strlen(s1) ≤≤ strlen(s2) It is always safe to use strncmp(s1, s2, m1 - 1). strlen(s1) is m1−1m1−1.

It is always safe to use strncmp(s1, s2, m1 - 1).

Given the following input John Smith what's the output of the following program? #include <stdio.h> int main() { char name1[4]; char name2[4]; // use fgets to read in name and address fgets(name1, 4, stdin); fgets(name2, 4, stdin); printf("%s %s", name1, name2);} Joh n John Smit John Smit Joh n

Joh n

Given the following input John Smith what's the output of the following program? #include <stdio.h> int main() { char name1[8]; char name2[8]; // use fgets to read in name and address fgets(name1, 8, stdin); fgets(name2, 8, stdin); printf("%s %s", name1, name2);} John Smith JohnSmith John Smith John Smith

John Smith

Given the following input John Smith what's the output of the following program? #include <stdio.h> int main() { char name1[8]; char name2[8]; // use fgets to read in name and address scanf("%s", name1); scanf("%s", name2); printf("%s %s", name1, name2); } John Smith John Smith John Smith John Smith

John Smith

What's the output of the following program? #include <stdio.h> #include <string.h> int main() { char name1[20] = "John "; char name2[] = "Smith"; strcat(name1, name2); printf("%s", name1);} John Smith John Smith Compile error on line 6. Cannot determine.

John Smith

To enter an arbitrary size of string into a char array, which of the following may be used to make sure ther eis no overflow? Use strlen to determine the number of input characters. Keep a counter on the number of read lines. Make sure each character is not new line character. Keep a counter on the number of read characters.

Keep a counter on the number of read characters.

Choose all correct statements about the following statement. char greetings[] = "Hello!"; The size of the array is 7. strlen(greetings) is 6. It is not a C-string, because it is not terminated by NULL. It is not a C-string, because it cannot contain special character !.

The size of the array is 7. strlen(greetings) is 6.

Analyze the following code. int main() { char str[]={"C","S","T","\0"}; printf("%s",str); return 0;} which of the following best describes the above code? It displays C, S, T There is a compile error. It displays CST It displays CST\0

There is a compile error.

What is a string in C Language? string is an array of characters with null character at the first index in the array. string is an array of characters with a null character before the end of the array. string is an array of characters with null character at the last index in the array. string is a primitive type C

string is an array of characters with a null character before the end of the array.

Analyze the following code segment. char str1[] = "abc"; char str2[] = {'a', 'b', 'c'}; which of the following statements is true? strlen(str2) will always return 3. strlen(str1) will always return 3. Both of them are C-strings. strcmp(str1, str2) will always return 0.

strlen(str1) will always return 3.

True or false: The maximum length of a C String is 128. true false

true

What is the return type of function strstr? char* int int* char

char*

What is the return type of the function strstr in the C-string library? char* char string int

char*

Which of the following is NOT a correct way to declare and initialize a C-string variable? char s[8] = "abcdef"; char s[] = "abcdef"; char* s = "abcdef"; char* s[10] = "abcdef";

char* s[10] = "abcdef";

What is the output of the following program? #include <stdio.h> #include <string.h> int main() { printf(strstr("abcdefg", "def")); } defg g def There is no output.

defg

What's the output of the following code segment? printf("%s", "Hello" + 1);

ello

What is the output of the following code? #include <stdio.h> #include <string.h> int main() { char str1[] = "hello"; char str2[20]; strcpy(str2, str1); printf("%s ", str2); printf("%d ", (str1 != str2)); printf("%d", strcmp(str1, str2)); return 0;} hello 0 0 hello 1 0 hello 1 0 hello\0 1 0

hello 1 0

Which of the following is a valid copy function in C-string library? memcopy strcopy memcpy memstrcpy

memcpy

To set a character array char buf[512] to all 0, which of the following is a correct and most efficient solution? for (int i = 0; i < 512; i++) { buf[i] = '\0'; } 3.memcpy(buf, 0, 512); for (int i = 0; i < 128; i++) { buf[i] = 0; } memset(buf, 0, 512);

memset(buf, 0, 512);

What is the use of function char *strchr(str, ch)? returns the index of the last occurrence of ch in str or NULL if not present returns the index of the first occurrence of ch in str or NULL if not present returns the pointer to first occurrence of ch in str or NULL if not present returns the pointer to last occurrence of ch in str or NULL if not present

returns the pointer to first occurrence of ch in str or NULL if not present

Which function will join two words? strcpy strcat strncon memcon

strcat

Match the string functions with the descriptions.

strcat - concatenates two strings strcmp - compares the strings lexicographically strlen - returns the length of a string strcpy - copies the content of one string to another strchr - searches the first occurence of a character in a string

Which of the following statement is true after sorting a string array with num elements? strcmp(all[i], all[i+1]) <= 0 for all i from 0 to num - 2. strcmp(all[i], all[i+1]) <= 0 for all i from 0 to num - 1. strcmp(all[i], all[i+1]) >= 0 for all i from 1 to num - 1. strcmp(all[i], all[i+1]) > 0 for all i from 0 to num - 2.

strcmp(all[i], all[i+1]) <= 0 for all i from 0 to num - 2.


संबंधित स्टडी सेट्स

Economics Honors Semester 1 - Three Economic Questions

View Set

Herbivore, Carnivore, or Omnivore ?

View Set

CNA 101 | Ch. 11, Building a Small Network

View Set