- reading and writing
- it works only for directory
- only for reading
Explanation:
The function fopen is responsible for opening files, with the mode "r+" indicating that the file must already exist and can be accessed for both reading and writing operations.
Hence, file manipulation involves reading and writing tasks carried out using the fopen function in the "r+" mode.
12) Which is used in mode string for opening the file in binary mode?
Explanation:
To engage binary mode when opening a file, the letter 'b' is included in the mode string. Binary mode is employed for conducting unstructured data input and output operations on a file.
13) Which of the following statement is correct?
- strcmp(s1, s2) returns 0 if s1==s2
- strcmp(s1, s2) returns 1 if s1==s2
- strcmp(s1, s2) returns a number less than 0 if s1>s2
- strcmp(s1, s2) returns a number greater than 0 if s1<s2
Explanation:
On comparing the two string, the values return by a function strcmp are:
- If, str1 is equal to str2 then Return value = 0
- If, str1 is greater than str2 then Return value > 0
- If, str1 is less than str2 then Return value < 0
The strcmp function returns an integer value, and according to the provided information, only option (a) is accurate, which means strcmp(s1, s2) will return 0 when s1 is equal to s2.
14) What will be the output of the below program?
#include<stdio.h>
#include<string.h>
int main()
{
char stri[] = "Java\0\Logic Practice\0";
printf("%s\n", stri);
return 0;
}
- Logic Practice
- Java
- Logic Practice
- Java\0Logic Practice
Explanation:
A string is a sequence of characters ending with the null character '\0'.
Declare the array of characters named stri with the initial value "Java\0\Logic Practice\0".
Step 2: By using the printf function with the format specifier %s, the variable stri is displayed on the screen.
Therefore the output of the program is Java.
15) What will be the output of the below program?
#include <stdio.h>
void main()
{
char ch[10]={'h', 'e', 'l', 'l', 'o', '\0'};
char ch2[10]={'c', '\0'};
strcat(ch,ch2);
printf("Value of first string is: %s",ch);
}
- hello
- helloc
- Compile error
Explanation:
The strcat method is employed for merging strings. When strcat(firststring, secondstring) is executed, it combines two strings, and the output is then stored back into first_string.
Therefore the output of the program is helloc.