Worksheetsstrlen(), strcpy(), strcat()
Total questions: 15
Worksheet time: 30mins
What will be the output of the following C code?
#include <stdio.h>
#include <string.h>
int main()
{
char *str = "hello, world";
char *str1 = "hello, world";
if (strcmp(str, str1))
printf("equal");
else
printf("unequal");
}
equal
unequal
Compilation error
Depends on the compiler
What will be the output of the following C code?
#include <stdio.h>
#include <string.h>
int main()
{
char *str = "hello, world";
char str1[15] = "hello wo 9";
strcpy(str, str1);
printf("%s", str1);
}
Compilation error
Segmentation Fault
hello, world
hello, wo 9
What will be the output of the following C code?
#include <stdio.h>
#include <string.h>
int main()
{
char *str = "hello, world";
char str1[9];
strncpy(str1, str, 9);
printf("%s %d", str1, strlen(str1));
}
hello, world 11
hello, wor 9
Undefined behaviour
Compilation error
What will be the output of the following C code?
#include <stdio.h>
#include <string.h>
int main()
{
char *str = "hello, world\n";
printf("%d", strlen(str));
}
Compilation error
Undefined behaviour
13
11
What will be the output of the following C code?#include <stdio.h>
#include <string.h>
int main()
{
char str[11] = "hello";
char *str1 = "world";
strcat(str, str1);
printf("%s %d", str, str[10]);
}
helloworld 0
helloworld anyvalue
worldhello 0
Segmentation fault/code crash
Strcat() function adds null character.
Only if there is space
Always
Depends on the standard
Depends on the compiler
What will be the output of the following C code?
#include <stdio.h>
#include <string.h>
int main()
{
char str[10] = "hello";
char *str1 = "world";
strncat(str, str1, 9);
printf("%s", str);
}
helloworld
Undefined behaviour
helloworl
hellowor
Which among the following is Copying function?
memcpy()
strcopy()
memcopy()
strxcpy()
Which function will you choose to join two words?
strcpy()
strcat()
strncon()
memcon()
The ______ function appends not more than n characters.
strcat()
strcon()
strncat()
memcat()
What will strcmp() function do?
compares the first n characters of the object
compares the string
undefined function
copies the string
Which of the following is the variable type defined in header string. h?
sizet
size
size_t
size-t
What is the prototype of strcoll() function?
int strcoll(const char s1,const char s2)
int strcoll(const char *s1)
int strcoll(const s1,const s2)
int strcoll(const *s1)
What is the function of strcoll()?
compares the string, result is dependent on the LC_COLLATE
copies the string, result is dependent on the LC_COLLATE
compares the string, result is not dependent on the LC_COLLATE
copies the string, result is not dependent on the LC_COLLATE
What will be the output of the following C code snippet?
const char pla[] = "string1";
const char pla[] = "string1";
const char src[] = "string2";
printf("Before memmove place= %s, src = %s ", pla, src);
memmove(pla, src, 7);
printf("After memmove place = %s, src = %s\n", pla, src);
Before memmove place= string1, src = string2 After memmove place = string2, src = string2
Before memmove place = string2, src = string2 After memmove place= string1, src = string2
Before memmove place = string2, src = string1 After memmove place= string2, src =string2
Before memmove place= string1, src = string2 After memmove place=string1, src = string1
