include<string.h>
int main
{
printf("%d\n", strlen("javaLogic Practice"));
return 0;
}
Example
- Compile error
The correct option is (b).
Explanation:
The function strlen() returns the number of character in the string.
Therefore, strlen("javaLogic Practice") returns 10
Hence the output of the program is "10".
## 7) Which of the following statements are correct about string?
- The format specifier %s is used to print a string.
- The length of the string can be obtained by strlen().
- The pointer cannot work on string.
- A string is a collection of characters terminated by '\0'.
- 1, 4
- 1, 2, 3
- 1, 2, 4
- 2, 3, 4
The correct option is (c).
Explanation:
Clearly the statement 1, 2 and 4 are correct about the string but the statement 3 is incorrect because we can use pointer on strings.
For example: char *p="javaLogic Practice"
## 8) For the following statements will arr[2] and ptr[2] fetch the same character?
char arr = "javaLogic Practice"
char *ptr = "javaLogic Practice"
Example
The correct option is (b).
Explanation:
Yes, for arr[2] and ptr[2] both the statements will prints the same character 'v'.
## 9) Which of the statements are correct about the below program?
include<stdio.h>
int main
{
char stri[20], *p;
printf("Enter the string\n:");
scanf("%s", stri);
p=stri;
while(*p != '\0')
{
if(p >= 97 && p <= 122)
p = p-32;
p++;
}
printf("%s",stri);
return 0;
}
Example
- The code converts lower case character to upper case
- The code converts upper case character to lower case
- The code converts a string to an integer
- Compile Time error
The correct option is (a).
Explanation:
The program converts the enter string to upper case string.
Output:
Enter the string: javaLogic Practice
LOGIC PRACTICE
Example
## 10) Determine the wrong file opening mode from the following.
The correct option is (c).
Explanation:
The file opening mode "x" is invalid as it does not exist for file operations in the C programming language.