quiz on strings
TRANSCRIPT
It’s Quiz Time
By Bhavya Singhal
Part-1Find out the
Correct Option
1. strinit() 2. strnset()
3. strset() 4. strcset()
Which of the following function sets first n characters of a string to a given character?
1. “-1” 2. “1”
3. 0 4. Yes
If the two strings are identical, then strcmp() function returns
1. printf("\n"); 2. echo "\\n";
3. printf('\n'); 4. printf("\\n");
How will you print \n on the screen?
1. strnstr() 2. laststr()
3. strrchr() 4. strstr()
The library function used to find the last occurrence of a character in a string is
1. strchr() 2. strrchr()
3. strstr() 4. strnset()
Which of the following function is used to find the first occurrence of a given string in another string?
1. printf(); 2. scanf();
3. gets(); 4. puts();
Which of the following function is more appropriate for reading in a multi-word string?
2. int xstrlen(char s) { int length=0; while(*s!='\0') length++; s++; return (length); }
3. int xstrlen(char *s) { int length=0; while(*s!='\0') length++; return (length); }
4. int xstrlen(char *s) { int length=0; while(*s!='\0') s++; return (length); }
Which of the following function is correct that finds the length of a string?1. int xstrlen(char *s) { int length=0; while(*s!='\0') { length++; s++; } return (length); }
Part-2Tell Yes or No
Will the program compile successfully?
#include<stdio.h>int main(){ char a[] = "India"; char *p = "BIX"; a = "BIX"; p = "India"; printf("%s %s\n", a, p); return 0;}
Yes or No
For the following statements will arr[3] and ptr[3] fetch the same character?char arr[] = "IndiaBIX";
&char *ptr = "IndiaBIX";
Yes or No
Is there any difference between the two statements?char *ch = "IndiaBIX";
&char ch[] = "IndiaBIX";
Yes or No
Is there any difference between the two statements?char *ch = "IndiaBIX";
&char ch[] = "IndiaBIX";
Yes or No
Part-3Find Out the Output
What will be the output of the program ?#include<stdio.h>#include<string.h>
int main(){ char str1[20] = "Hello", str2[20] = " World"; printf("%s\n", strcpy(str2, strcat(str1, str2))); return 0;}
1. Hello 2. World
3. Hello World 4. WorldHello
What will be the output of the program ?#include<stdio.h>
int main(){ printf(5+"Good Morning\n"); return 0;}
1. Good Morning 2. Good
3. M 4. Morning
1. BIX 2. India
3. India Bix 4. India\0Bix
What will be the output of the program ?#include<stdio.h>#include<string.h>
int main(){ char str[] = "India\0\BIX\0"; printf("%s\n", str); return 0;}
Acknowledgment 1.http://www.indiabix.com/
2.https://www.tutorialspoint.com//cprogramming/c_strings.htm
Thank You