Strings are actually one-dimensional array of characters terminated by a null character '\0'. Thus a null-terminated string contains the characters that comprise the string followed by a null.
Eg.
#include
int main () {
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
printf("Greeting message: %s\n", greeting );
return 0;
}
--------------------------------------------------------------------------------------------------------------
Next Page Home Last Page
--------------------------------------------------------------------------------------------------------------
1.
If the two strings are identical, then strcmp() function returns
A. -1
B. 1
C. 0
D. Yes
Answer: C
------------------------------------------------------------------------------------------------------------
2.
The library function used to find the last occurrence of a character in a string is
A. strnstr()
B. laststr()
C. strrchr()
D. strstr()
Answer: C
-----------------------------------------------------------------------------------------------------------
3.
Which of the following function is correct that finds the length of a string?
A. int xstrlen(char *s)
{
int length=0;
while(*s!='\0')
{
length++; s++; }
return (length);
}
B. int xstrlen(char s)
{
int length=0;
while(*s!='\0')
length++; s++;
return (length);
}
C. int xstrlen(char *s)
{
int length=0;
while(*s!='\0')
s++;
return (length);
}
D. int xstrlen(char *s)
{
int length=0;
while(*s!='\0')
length++;
return (length);
}
Answer: A
----------------------------------------------------------------------------------------------------
4.
Which of the following function is more appropriate for reading in a multi-word string?
A. printf();
B. scanf();
C. gets();
D. puts();
Answer: C
--------------------------------------------------------------------------------------------------------
5.
What will be the output ?
#include
#include
int main()
{
char str1[20] = "Hello", str2[20] = " World";
printf("%s\n", strcpy(str2, strcat(str1, str2)));
return 0;
}
A. Hello
B. World
C. Hello World
D. WorldHello
Answer: C
-----------------------------------------------------------------------------------------------------------
Home Next Page Last Page
-----------------------------------------------------------------------------------------------------------
More Imp Topics:
Array
Preprocessor
Structures
Control Structures
Switch Case
Printf
Variables
File Handling