C String Test 3


11) Function fopen() with the mode "r+" used to open a file for _______

  1. reading and adding new content
  2. reading and writing
  3. it works only for directory
  4. only for reading

The correct option is (b).

Explanation:

Function fopen() opens the file and mode "r+" used for checking the file should exist and opens for both reading writing operation.

Therefore in file handling reading and writing operation is performed by function fopen() with the mode "r+".

12) Which is used in mode string for opening the file in binary mode?

  1. a
  2. B
  3. b
  4. bin

The correct option is (c).

Explanation:

For opening the file in binary mode the alphabet 'b' is used in mode string. To perform unformatted data I/O a file is opened in binary mode.

13) Which of the following statement is correct?

  1. strcmp(s1, s2) returns 0 if s1==s2
  2. strcmp(s1, s2) returns 1 if s1==s2
  3. strcmp(s1, s2) returns a number less than 0 if s1>s2
  4. strcmp(s1, s2) returns a number greater than 0 if s1<s2

The correct option is (a).

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() return an int value and from the given statement only statement (a) is correct i.e. strcmp(s1, s2) returns 0 if s1==s2

14) What will be the output of the below program?

  1. Tpoint
  2. Java
  3. Java Tpoint
  4. Java\0Tpoint

The correct option is (b).

Explanation:

The string is a collection of characters terminated by '\0'.

Step 1: char stri[] = "Java\0\Tpoint\0"; The variable stri is declared as an array of characters and it is initialized with value "Java".

Step 2: printf("%s\n", stri); it print the value of stri.

Therefore the output of the program isJava.

15) What will be the output of the below program?

  1. hello
  2. c
  3. helloc
  4. Compile error

The correct option is (c).

Explanation:

The strcat() function is used for string concatenation. The strcat(first_string, second_string) function concatenates two strings and result is returned to first_string.

Therefore the output of the program is helloc.





Latest Courses