NEW
Font size
WorksheetsC - Strings
Total questions: 20
Worksheet time: 20mins
What is the return value of the following statement if it is placed in C program? strcmp(“ABC”,”ABC”);
33
-1
1
0
Which built in function is used to convert string to lowercase
strlen()
strlwr()
strcmp()
strrev()
Which is not a built in function
string()
strlen()
strcat()
strrev()
String is an array of characters with …….. character as the last element of array.
Null
Empty
0
1
What is the format specifier used to print or read a character in an array in Printf or Scanf function?
%C
%f
%w
%c
Which of the following function is more appropriate for reading in a multi-word string?
scanf()
gets()
printf()
puts()
The library function used to copy a string to another is
strncpy()
strcmp()
strcpy()
strchr()
String is initialized with datatype
float
char
int
double
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 below program
#include <stdio.h>
#include <string.h>
int main( )
{
char source[ ] = " fresh2refresh" ;
char target[ ]= " C tutorial" ;
strcat ( target, source ) ;
printf ( "\nTarget string after strcat( ) = %s", target ) ;
}
Target string after strcat( ) = fresh2refresh
Target string after strcat( ) = C tutorial
Target string after strcat( ) =
Target string after strcat( ) = C tutorial fresh2refresh
What is the output of this program?
#include <stdio.h>
int main()
{
char str[] = "hello, world";
printf("%d", strlen(str));
}
Compilation error
10
13
12
What is the output of
#include <stdio.h>
int main()
{
char str[8]="IncludeHelp";
printf("%s",str);
return 0;
}
IncludeHelp
IncludeH
Error
No Output
What is the output of this
#include <stdio.h>
#include <string.h>
int main()
{
char s1[10] = "Hello";
char s2[10] = "World";
strncat(s1,s2, 3);
printf("Concatenation using strncat: %s", s1);
return 0;
}
Concatenation using strncat: Hel
Concatenation using strncat: HelloWorld
Concatenation using strncat: HelloWor
None of the above
What is the output of
#include <stdio.h>
#include <string.h>
int main()
{
char s1[30] = "string 1";
char s2[30] = "string 2: Am using strncpy now";
strncpy(s1,s2, 12);
printf("String s1 is: %s", s1);
return 0;
}
String s1 is: string 2: Am
String s1 is: string 2: A
String s1 is: string 2:
None of the above
What is the output of the below program
#include <stdio.h>
#include <string.h>
int main()
{
char str1[] = "abcd", str2[] = "abcd";
int result;
result = strcmp(str1, str2);
printf("strcmp(str1, str2) = %d\n", result);
return 0;
}
0
1
Invalid
None of the above
What is the output of the below program
#include <stdio.h>
#include <ctype.h>
void strupr(char s[])
{
int i = 0;
while(s[i] != '\0')
{
printf("%c",toupper(s[i]));
i++;
}
printf("\n");
}
int main()
{
strupr("Hello Shivamogga");
return 0;
}
Hello Shivamogga
HELLO Shivamogga
Error
HELLO SHIVAMOGGA
What is the output of the below program
#include <stdio.h>
int main()
{
char str[ ] = "Hello";
int i;
for( i=2; i<4; i++)
{
printf("%c", str[i]);
}
return 0;
}
He
ll
el
lo
What will be the output of the below program
#include <stdio.h>
int main()
{
int a[5]={5,1,15,20,25};
int i,j,m;
i=++a[1];
j=a[1]++;
m=a[i++];
printf("%d,%d,%d",i,j,m);
}
3,2,15
2,3,20
2,1,15
1,2,5
What is the output of the below program
#include <stdio.h>
int main()
{
char str[]="JNNCE", ch='N';
int i, frequency = 0;
for(i = 0; str[i] != '\0'; ++i)
{
if(ch == str[i])
++frequency;
}
printf("Frequency of %c = %d", ch, frequency);
return 0;
}
Frequency of N = 0
Frequency of N = -1
Frequency of N = 2
None of the above
The library function used to calculate the length of the string is
strstr()
strrev()
strlen()
strcat()
