Java C String Test 2 | 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 2 | Core Java Quiz | Free Java Online Test and Clear your Basic fundamentals easily. Java C String Quiz 2, Free Java C String Online Test 2019. Java C String Quiz 2 Question and Answers 2019. Java online Test Quiz 2. Java C String Quiz 2 Free Mock Test 2019. Java C String Quiz 2 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 2 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
What will be the output of the program ?
#include
#includeint main()
{
static char s[] = “Hello!”;
printf(“%d “, *(s+strlen(s)));
return 0;
}Correct
Incorrect
-
Question 2 of 20
2. Question
What will be the output of the program ?
#include
int main()
{
char str[7] = “JavaTpoint”;
printf(“%s “, str);
return 0;
}Correct
Here str[] has declared as 7 character array and into a 8 character is stored. This will result in overwriting of the byte beyond 7 byte reserved for ´´.
Incorrect
Here str[] has declared as 7 character array and into a 8 character is stored. This will result in overwriting of the byte beyond 7 byte reserved for ´´.
-
Question 3 of 20
3. Question
What will be the output of the program ?
#include
int main()
{
static char mess[6][30] = {“Don´t walk in front of me…”,
“I may not follow;”,
“Don´t walk behind me…”,
“Just walk beside me…”,
“And be my friend.” };printf(“%c, %c “, *(mess[2]+9), *(*(mess+2)+9));
return 0;
}Correct
Incorrect
-
Question 4 of 20
4. Question
What will be the output of the program ?
#include
#includeint main()
{
char str[] = “JavaTpoint”;
printf(“%d “, strlen(str));
return 0;
}Correct
The function strlen returns the number of characters int the given string.
Incorrect
The function strlen returns the number of characters int the given string.
-
Question 5 of 20
5. Question
What will be the output of the program ?
#include
int main()
{
int i;
char a[] = “”;
if(printf(“%s”, a))
printf(“The string is empty “);
else
printf(“The string is not empty “);
return 0;
}Correct
The function printf() returns the number of charecters printed on the console.
Step 1: char a[] = “”; The variable a is declared as an array of characters and it initialized with “”. It denotes that the string is empty.
Step 2: if(printf(“%s”, a)) The printf() statement does not print anything, so it returns 0. Hence the if condition is failed.
In the else part it prints “The string is not empty”.Incorrect
The function printf() returns the number of charecters printed on the console.
Step 1: char a[] = “”; The variable a is declared as an array of characters and it initialized with “”. It denotes that the string is empty.
Step 2: if(printf(“%s”, a)) The printf() statement does not print anything, so it returns 0. Hence the if condition is failed.
In the else part it prints “The string is not empty”. -
Question 6 of 20
6. Question
What will be the output of the program ?
#include
#includeint main()
{
static char str1[] = “dills”;
static char str2[20];
static char str3[] = “Daffo”;
int i;
i = strcmp(strcat(str3, strcpy(str2, str1)), “Daffodills”);
printf(“%d “, i);
return 0;
}Correct
Incorrect
-
Question 7 of 20
7. Question
What will be the output of the program ?
#include
int main()
{
static char s[25] = “The cocaine man”;
int i=0;
char ch;
ch = s[++i];
printf(“%c”, ch);
ch = s[i++];
printf(“%c”, ch);
ch = i++[s];
printf(“%c”, ch);
ch = ++i[s];
printf(“%c”, ch);
return 0;
}Correct
Incorrect
-
Question 8 of 20
8. Question
If char=1, int=4, and float=4 bytes size, What will be the output of the program ?
#include
int main()
{
char ch = ´A´;
printf(“%d, %d, %d”, sizeof(ch), sizeof(´A´), sizeof(3.14f));
return 0;
}Correct
Step 1: char ch = ´A´; The variable ch is declared as an character type and initialized with value ´A
Incorrect
Step 1: char ch = ´A´; The variable ch is declared as an character type and initialized with value ´A
-
Question 9 of 20
9. Question
What will be the output of the program in 16-bit platform (Turbo C under DOS) ?
#include
int main()
{
printf(“%d, %d, %d”, sizeof(3.0f), sizeof(´3´), sizeof(3.0));
return 0;
}Correct
printf(“%d, %d, %d”, sizeof(3.0f), sizeof(´3´), sizeof(3.0));
The sizeof function returns the size of the given expression.
sizeof(3.0f) is a floating point constant. The size of float is 4 bytes
sizeof(´3´) It converts ´3´ in to ASCII value.. The size of int is 2 bytes
sizeof(3.0) is a double constant. The size of double is 8 bytes
Hence the output of the program is 4,2,8
Note: The above program may produce different output in other platform due to the platform dependency of C compiler.
In Turbo C, 4 2 8. But in GCC, the output will be 4 4 8.Incorrect
printf(“%d, %d, %d”, sizeof(3.0f), sizeof(´3´), sizeof(3.0));
The sizeof function returns the size of the given expression.
sizeof(3.0f) is a floating point constant. The size of float is 4 bytes
sizeof(´3´) It converts ´3´ in to ASCII value.. The size of int is 2 bytes
sizeof(3.0) is a double constant. The size of double is 8 bytes
Hence the output of the program is 4,2,8
Note: The above program may produce different output in other platform due to the platform dependency of C compiler.
In Turbo C, 4 2 8. But in GCC, the output will be 4 4 8. -
Question 10 of 20
10. Question
What will be the output of the program ?
#include
int main()
{
char *names[] = { “Suresh”, “Siva”, “Sona”, “Baiju”, “Ritu”};
int i;
char *t;
t = names[3];
names[3] = names[4];
names[4] = t;
for(i=0; i printf(“%s,”, names[i]);
return 0;
}Correct
Step 1: char *names[] = { “Suresh”, “Siva”, “Sona”, “Baiju”, “Ritu”}; The variable names is declared as an pointer to a array of strings.
Step 2: int i; The variable i is declared as an integer type.
Step 3: char *t; The variable t is declared as pointer to a string.
Step 4: t = names[3]; names[3] = names[4]; names[4] = t; These statements the swaps the 4 and 5 element of the array names.
Step 5: for(i=0; iIncorrect
Step 1: char *names[] = { “Suresh”, “Siva”, “Sona”, “Baiju”, “Ritu”}; The variable names is declared as an pointer to a array of strings.
Step 2: int i; The variable i is declared as an integer type.
Step 3: char *t; The variable t is declared as pointer to a string.
Step 4: t = names[3]; names[3] = names[4]; names[4] = t; These statements the swaps the 4 and 5 element of the array names.
Step 5: for(i=0; i -
Question 11 of 20
11. Question
What will be the output of the program ?
#include
int main()
{
char str[] = “Nagpur”;
str[0]=´K´;
printf(“%s, “, str);
str = “Kanpur”;
printf(“%s”, str+1);
return 0;
}Correct
The statement str = “Kanpur”; generates the LVALUE required error. We have to use strcpy function to copy a string.
To remove error we have to change this statement str = “Kanpur”; to strcpy(str, “Kanpur”);
The program prints the string “anpur”Incorrect
The statement str = “Kanpur”; generates the LVALUE required error. We have to use strcpy function to copy a string.
To remove error we have to change this statement str = “Kanpur”; to strcpy(str, “Kanpur”);
The program prints the string “anpur” -
Question 12 of 20
12. Question
What will be the output of the program ?
#include
int main()
{
int i;
char a[] = “”;
if(printf(“%s”, a))
printf(“The string is not empty “);
else
printf(“The string is empty “);
return 0;
}Correct
Incorrect
-
Question 13 of 20
13. Question
What will be the output of the program ?
#include
int main()
{
char str1[] = “Hello”;
char str2[10];
char *t, *s;
s = str1;
t = str2;
while(*t=*s)
*t++ = *s++;
printf(“%s “, str2);
return 0;
}Correct
Incorrect
-
Question 14 of 20
14. Question
What will be the output of the program ?
#include
#includeint main()
{
char str1[5], str2[5];
int i;
gets(str1);
gets(str2);
i = strcmp(str1, str2);
printf(“%d “, i);
return 0;
}Correct
gets() gets collects a string of characters terminated by a new line from the standard input stream stdin.
The gets(str1) read the input string from user and store in variable str1.
The gets(str2) read the input string from user and store in variable str2.
The code i = strcmp(str1, str2); The strcmp not only returns -1, 0 and +1, but also other negative or positive values. So the value of i is “unpredictable integer value”.
printf(“%d “, i); It prints the value of variable i.Incorrect
gets() gets collects a string of characters terminated by a new line from the standard input stream stdin.
The gets(str1) read the input string from user and store in variable str1.
The gets(str2) read the input string from user and store in variable str2.
The code i = strcmp(str1, str2); The strcmp not only returns -1, 0 and +1, but also other negative or positive values. So the value of i is “unpredictable integer value”.
printf(“%d “, i); It prints the value of variable i. -
Question 15 of 20
15. Question
What will be the output of the program ?
#include
int main()
{
char str1[] = “Hello”;
char str2[] = “Hello”;
if(str1 == str2)
printf(“Equal “);
else
printf(“Unequal “);
return 0;
}Correct
Step 1: char str1[] = “Hello”; The variable str1 is declared as an array of characters and initialized with a string “Hello”.
Step 2: char str2[] = “Hello”; The variable str2 is declared as an array of characters and initialized with a string “Hello”.
We have use strcmp(s1,s2) function to compare strings.
Step 3: if(str1 == str2) here the address of str1 and str2 are compared. The address of both variable is not same. Hence the if condition is failed.
Step 4: At the else part it prints “Unequal”.Incorrect
Step 1: char str1[] = “Hello”; The variable str1 is declared as an array of characters and initialized with a string “Hello”.
Step 2: char str2[] = “Hello”; The variable str2 is declared as an array of characters and initialized with a string “Hello”.
We have use strcmp(s1,s2) function to compare strings.
Step 3: if(str1 == str2) here the address of str1 and str2 are compared. The address of both variable is not same. Hence the if condition is failed.
Step 4: At the else part it prints “Unequal”. -
Question 16 of 20
16. Question
If the size of pointer is 4 bytes then What will be the output of the program ?
#include
int main()
{
char *str[] = {“Frogs”, “Do”, “Not”, “Die”, “They”, “Croak!”};
printf(“%d, %d”, sizeof(str), strlen(str[0]));
return 0;
}Correct
Step 1: char *str[] = {“Frogs”, “Do”, “Not”, “Die”, “They”, “Croak!”}; The variable str is declared as an pointer to the array of 6 strings.
Step 2: printf(“%d, %d”, sizeof(str), strlen(str[0]));
sizeof(str) denotes 6 * 4 bytes = 24 bytes. Hence it prints ´24´
strlen(str[0])); becomes strlen(Frogs)). Hence it prints ´5´;
Hence the output of the program is 24, 5
Hint: If you run the above code in 16 bit platform (Turbo C under DOS) the output will be 12, 5. Because the pointer occupies only 2 bytes. If you run the above code in Linux (32 bit platform), the output will be 24, 5 (because the size of pointer is 4 bytes).Incorrect
Step 1: char *str[] = {“Frogs”, “Do”, “Not”, “Die”, “They”, “Croak!”}; The variable str is declared as an pointer to the array of 6 strings.
Step 2: printf(“%d, %d”, sizeof(str), strlen(str[0]));
sizeof(str) denotes 6 * 4 bytes = 24 bytes. Hence it prints ´24´
strlen(str[0])); becomes strlen(Frogs)). Hence it prints ´5´;
Hence the output of the program is 24, 5
Hint: If you run the above code in 16 bit platform (Turbo C under DOS) the output will be 12, 5. Because the pointer occupies only 2 bytes. If you run the above code in Linux (32 bit platform), the output will be 24, 5 (because the size of pointer is 4 bytes). -
Question 17 of 20
17. Question
What will be the output of the program ?
#include
int main()
{
char str[] = “JavaTpoint”;
printf(“%d “, sizeof(str));
return 0;
}Correct
Incorrect
-
Question 18 of 20
18. Question
What will be the output of the program ?
#include
int main()
{
char str = “JavaTpoint”;
printf(“%s “, str);
return 0;
}Correct
The line char str = “JavaTpoint”; generates “Non portable pointer conversion” error.
Incorrect
The line char str = “JavaTpoint”; generates “Non portable pointer conversion” error.
-
Question 19 of 20
19. Question
What will be the output of the program ?
#include
int main()
{
char str[25] = “JavaTpoint”;
printf(“%s “, &str+2);
return 0;
}Correct
Incorrect
-
Question 20 of 20
20. Question
What will be the output of the program ?
#include
#includeint main()
{
char sentence[80];
int i;
printf(“Enter a line of text “);
gets(sentence);
for(i=strlen(sentence)-1; i >=0; i–)
putchar(sentence[i]);
return 0;
}Correct
Incorrect