Java C String Test 1 | Core Java Quiz | Free Java Online Test
Finish Quiz
0 of 20 questions completed
Questions:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
Information
Let’s Play with our free Java C String Test 1 | Core Java Quiz | Free Java Online Test and Clear your Basic fundamentals easily. Free Java C String Quiz. Java C String Question and Answers 2024. Java online Test Quiz 1. Java C String Quiz 1 Free Mock Test 2024. Java C String Quiz 1 Question and Answers in PDF. The Java online mock test paper is free for all students. Spring Online is very useful for exam preparation and getting for Rank. Java C String Quiz 1 Question and Answers in English. Java C String Mock test for topic via C String Mode. Here we are providing Java C String Quiz in English Now Test your self for “C String Online Quiz in English” Exam by using below quiz…
This paper has 20 questions.
Time allowed is 25 minutes.
The Java C String Mock Test is Very helpful for all students. Now Scroll down below n click on “Start Quiz” or “Start Test” and Test yourself.
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading...
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
Results
0 of 20 questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 points, (0)
Average score |
|
Your score |
|
Categories
- Not categorized 0%
Pos. | Name | Entered on | Points | Result |
---|---|---|---|---|
Table is loading | ||||
No data available | ||||
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- Answered
- Review
-
Question 1 of 20
1. Question
The library function used to find the last occurrence of a character in a string is
Correct
char *strrchr(const char *s, int c);
It scans a string s in the reverse direction, looking for a specific character c.
Example:
#include <string.h>
#include <stdio.h>int main(void)
{
char text[] = “I learn through IndiaBIX.com”;
char *ptr, c = ´i´;ptr = strrchr(text, c);
if (ptr)
printf(“The position of ´%c´ is: %d “, c, ptr-text);
else
printf(“The character was not found “);
return 0;
}
Output:The position of ´i´ is: 19
Incorrect
char *strrchr(const char *s, int c);
It scans a string s in the reverse direction, looking for a specific character c.
Example:
#include <string.h>
#include <stdio.h>int main(void)
{
char text[] = “I learn through IndiaBIX.com”;
char *ptr, c = ´i´;ptr = strrchr(text, c);
if (ptr)
printf(“The position of ´%c´ is: %d “, c, ptr-text);
else
printf(“The character was not found “);
return 0;
}
Output:The position of ´i´ is: 19
-
Question 2 of 20
2. Question
Will the program compile successfully?
#include<stdio.h>
int main()
{
char a[] = “Java”;
char *p = “Tpoint”;
a = “Java”;
p = “Tpoint”;
printf(“%s %s “, a, p);
return 0;
}Correct
Because we can assign a new string to a pointer but not to an array a.
Incorrect
Because we can assign a new string to a pointer but not to an array a.
-
Question 3 of 20
3. Question
For the following statements will arr[3] and ptr[3] fetch the same character?
char arr[] = “JavaTpoint”;
char *ptr = “JavaTpoint”;Correct
Yes, both the statements prints the same character a.
Incorrect
Yes, both the statements prints the same character a.
-
Question 4 of 20
4. Question
Which of the following function is more appropriate for reading in a multi-word string?
Correct
gets(); collects a string of characters terminated by a new line from the standard input stream stdin
Incorrect
gets(); collects a string of characters terminated by a new line from the standard input stream stdin
-
Question 5 of 20
5. Question
Which of the following statement is correct?
Correct
Incorrect
-
Question 6 of 20
6. Question
If the two strings are identical, then strcmp() function returns
Correct
strcmp(const char *s1, const char*s2);
The strcmp return an int value that is
if s1 < s2 returns a value < 0
if s1 == s2 returns 0
if s1 > s2 returns a value > 0Incorrect
strcmp(const char *s1, const char*s2);
The strcmp return an int value that is
if s1 < s2 returns a value < 0
if s1 == s2 returns 0
if s1 > s2 returns a value > 0 -
Question 7 of 20
7. Question
Is there any difference between the two statements?
char *ch = “JavaTpoint”;
char ch[] = “JavaTpoint”;Correct
In first statement the character pointer ch stores the address of the string “JavaTpoint”.
The second statement specifies the space for 7 characters be allocated and that the name of location is ch.Incorrect
In first statement the character pointer ch stores the address of the string “JavaTpoint”.
The second statement specifies the space for 7 characters be allocated and that the name of location is ch. -
Question 8 of 20
8. Question
Which of the following function is used to find the first occurrence of a given string in another string?
Correct
Incorrect
-
Question 9 of 20
9. Question
Which of the following function sets first n characters of a string to a given character?
Correct
char *strnset(char *s, int ch, size_t n); Sets the first n characters of s to ch
#include <stdio.h>
#include <string.h>int main(void)
{
char *string = “abcdefghijklmnopqrstuvwxyz”;
char letter = ´x´;printf(“string before strnset: %s “, string);
strnset(string, letter, 13);
printf(“string after strnset: %s “, string);return 0;
}
Output:string before strnset: abcdefghijklmnopqrstuvwxyz
string after strnset: xxxxxxxxxxxxxnopqrstuvwxyz
Incorrect
char *strnset(char *s, int ch, size_t n); Sets the first n characters of s to ch
#include <stdio.h>
#include <string.h>int main(void)
{
char *string = “abcdefghijklmnopqrstuvwxyz”;
char letter = ´x´;printf(“string before strnset: %s “, string);
strnset(string, letter, 13);
printf(“string after strnset: %s “, string);return 0;
}
Output:string before strnset: abcdefghijklmnopqrstuvwxyz
string after strnset: xxxxxxxxxxxxxnopqrstuvwxyz
-
Question 10 of 20
10. Question
How will you print on the screen?
Correct
The statement printf(“\n”); prints ´ ´ on the screen.
Incorrect
The statement printf(“\n”); prints ´ ´ on the screen.
-
Question 11 of 20
11. Question
Which of the following statements are correct about the program below?
#include<stdio.h>
int main()
{
char str[20], *s;
printf(“Enter a string “);
scanf(“%s”, str);
s=str;
while(*s != ´´)
{
if(*s >= 97 && *s <= 122)
*s = *s-32;
s++;
}
printf(“%s”,str);
return 0;
}Correct
This program converts the given string to upper case string.
Incorrect
This program converts the given string to upper case string.
-
Question 12 of 20
12. Question
Which of the following statements are correct about the below declarations?
char *p = “JavaTpoint”;
char a[] = “JavaTpoint”;
1: There is no difference in the declarations and both serve the same purpose.
2: p is a non-const pointer pointing to a non-const string, whereas a is a const pointer pointing to a non-const pointer.
3: The pointer p can be modified to point to another string, whereas the individual characters within array a can be changed.
4: In both cases the ´´ will be added at the end of the string “JavaTpoint”.Correct
Incorrect
-
Question 13 of 20
13. Question
What will be the output of the program ?
#include<stdio.h>
int main()
{
char p[] = “%d “;
p[1] = ´c´;
printf(p, 65);
return 0;
}Correct
Step 1: char p[] = “%d “; The variable p is declared as an array of characters and initialized with string “%d”.
Step 2: p[1] = ´c´; Here, we overwrite the second element of array p by ´c´. So array p becomes “%c”.
Step 3: printf(p, 65); becomes printf(“%c”, 65);
Therefore it prints the ASCII value of 65. The output is ´A´.Incorrect
Step 1: char p[] = “%d “; The variable p is declared as an array of characters and initialized with string “%d”.
Step 2: p[1] = ´c´; Here, we overwrite the second element of array p by ´c´. So array p becomes “%c”.
Step 3: printf(p, 65); becomes printf(“%c”, 65);
Therefore it prints the ASCII value of 65. The output is ´A´. -
Question 14 of 20
14. Question
What will be the output of the program ?
#include<stdio.h>
#include<string.h>int main()
{
printf(“%d “, strlen(“123456”));
return 0;
}Correct
The function strlen returns the number of characters in the given string.
Therefore, strlen(“123456”) returns 6.
Hence the output of the program is “6”.Incorrect
The function strlen returns the number of characters in the given string.
Therefore, strlen(“123456”) returns 6.
Hence the output of the program is “6”. -
Question 15 of 20
15. Question
What will be the output of the program If characters ´a´, ´b´ and ´c´ enter are supplied as input?
#include<stdio.h>
int main()
{
void fun();
fun();
printf(” “);
return 0;
}
void fun()
{
char c;
if((c = getchar())!= ´ ´)
fun();
printf(“%c”, c);
}Correct
Step 1: void fun(); This is the prototype for the function fun().
Step 2: fun(); The function fun() is called here.
The function fun() gets a character input and the input is terminated by an enter key(New line character). It prints the given character in the reverse order.
The given input characters are “abc”
Output: cbaIncorrect
Step 1: void fun(); This is the prototype for the function fun().
Step 2: fun(); The function fun() is called here.
The function fun() gets a character input and the input is terminated by an enter key(New line character). It prints the given character in the reverse order.
The given input characters are “abc”
Output: cba -
Question 16 of 20
16. Question
What will be the output of the program ?
#include<stdio.h>
#include<string.h>int main()
{
char str[] = “JavaTpoint”;
printf(“%s “, str);
return 0;
}Correct
A string is a collection of characters terminated by ´´.
Incorrect
A string is a collection of characters terminated by ´´.
-
Question 17 of 20
17. Question
What will be the output of the program ?
#include<stdio.h>
int main()
{
printf(5+”Good Morning “);
return 0;
}Correct
printf(5+”Good Morning “); It skips the 5 characters and prints the given string.
Hence the output is “Morning”Incorrect
printf(5+”Good Morning “); It skips the 5 characters and prints the given string.
Hence the output is “Morning” -
Question 18 of 20
18. Question
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 “, strcpy(str2, strcat(str1, str2)));
return 0;
}Correct
Step 1: char str1[20] = “Hello”, str2[20] = ” World”; The variable str1 and str2 is declared as an array of characters and initialized with value “Hello” and ” World” respectively.
Step 2: printf(“%s “, strcpy(str2, strcat(str1, str2)));
=> strcat(str1, str2)) it append the string str2 to str1. The result will be stored in str1. Therefore str1 contains “Hello World”.
=> strcpy(str2, “Hello World”) it copies the “Hello World” to the variable str2.
Hence it prints “Hello World”.Incorrect
Step 1: char str1[20] = “Hello”, str2[20] = ” World”; The variable str1 and str2 is declared as an array of characters and initialized with value “Hello” and ” World” respectively.
Step 2: printf(“%s “, strcpy(str2, strcat(str1, str2)));
=> strcat(str1, str2)) it append the string str2 to str1. The result will be stored in str1. Therefore str1 contains “Hello World”.
=> strcpy(str2, “Hello World”) it copies the “Hello World” to the variable str2.
Hence it prints “Hello World”. -
Question 19 of 20
19. Question
Which of the following statements are correct ?
1: A string is a collection of characters terminated by ´´.
2: The format specifier %s is used to print a string.
3: The length of the string can be obtained by strlen().
4: The pointer CANNOT work on string.Correct
Incorrect
-
Question 20 of 20
20. Question
What will be the output of the program ?
#include<stdio.h>
int main()
{
printf(“Java”, “Tpoint “);
return 0;
}Correct
printf(“Java”, “Tpoint “); It prints “Java”. Because ,(comma) operator has Left to Right associativity. After printing “Java”, the statement got terminated.
Incorrect
printf(“Java”, “Tpoint “); It prints “Java”. Because ,(comma) operator has Left to Right associativity. After printing “Java”, the statement got terminated.