C-Strings Question and Answer
C-Strings Question and Answer
1. Which of the following function sets first n characters of a string to a given character?
- strinit()
- strnset()
- strset()
- strcset()
3. How will you print \n on the screen?
- printf("\n");
- echo "\\n";
- printf('\n');
- printf("\\n");
4. The library function used to find the last occurrence of a character in a string is
- strnstr()
- laststr()
- strrchr()
- strstr()
5. Which of the following function is used to find the first occurrence of a given string in another string?
- strchr()
- strrchr()
- strstr()
- strnset()
6. Which of the following function is more appropriate for reading in a multi-word string?
- printf();
- scanf();
- gets();
- puts();
7. Which of the following function is correct that finds the length of a string?
- int xstrlen(char *s) { int length=0; while(*s!='\0') { length++; s++; } return (length); }
- int xstrlen(char s) { int length=0; while(*s!='\0') length++; s++; return (length); }
- int xstrlen(char *s) { int length=0; while(*s!='\0') length++; return (length); }
- int xstrlen(char *s) { int length=0; while(*s!='\0') s++; return (length); }
9. Given a declaration and initialization statement as shown below,
char a [200] = {'0';}
What is the output of the following printf statment ?
char a [200] = {'0';}
What is the output of the following printf statment ?
- 48 0 0
- 44 0 0
- 46 0
- 49 0 49 0
10. Given a declaration and initilization as shown below,
char a [6] = {'1', '2', '3', };
What is the output of the following printf statement ?
printf ("%c %c %c %c %c", a[0], a[3], a[4], a[2], a[4], a[1]);
char a [6] = {'1', '2', '3', };
What is the output of the following printf statement ?
printf ("%c %c %c %c %c", a[0], a[3], a[4], a[2], a[4], a[1]);
- 1 2 3 4 5 6 7
- 1 2 3 4 5
- 1 3 2
- 1 2 3 0 0 0