C String Test 4


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

  1. this is javatpoint with c and java
  2. javatpoint with c and java
  3. java
  4. compile error

The correct option is (b).

Explanation:

The strstr() function returns pointer to the first occurrence of the matched string in the given string. It is used to return substring from first match till the last character.

Syntax:

char *strstr(const char *string, const char *match)

string: It represents the full string from where substring will be searched.

match: It represents the substring to be searched in the full string.

Therefore the output of the above program is javatpoint with c and java.

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

  1. 5 9
  2. 9 20
  3. 2 9
  4. 2 5

The correct option is (c).

Explanation:

The strlen(x) function is used for finding the length of string 'x'. In program the length of string is count of character upto '\0'. Hence the string length output is 2.

The sizeof(x) function is used for finding the size of string 'x'. In program sizeof() returns the size of the complete array. Hence the size of array output is 9.

Therefore the combined output of the program is 2 9.

18) If the size of pointer is 4 bytes then what will be the output of below program?

  1. 22, 4
  2. 20, 4
  3. 20, 5
  4. 25,4

The correct option is (b).

Explanation:

Step 1: char *stri[] = {"Java", "C", "Android", "Embedded", "JS"}; The variable stri is declaraed as a pointer to the array of 5 strings.

Step 2: printf("%d, %d", sizeof(stri), strlen(stri[0]));

Sizeof(stri) denotes 5*4 bytes=20 bytes. Hence it prints '20'

Strlen(stri[0]) becomes strlen(Java). Hence it prints '4'.

Hence the output of the program is 20, 4.

19) What will be the output of below program?

  1. o
  2. t
  3. p
  4. Compile error

The correct option is (c).

Explanation:

The statement printf("%c\n", "javatpoint"[5]); prints the 6th character of the string "javatpoint".

Hence the output of a program is 'p'.

20) What will be the output of the below program in 16 bit platform assuming that 2022 is memory address of the string "Welcome" (in Turbo C under DOS)?

  1. 2022 Programming
  2. Welcome Programming
  3. Welcome 2022
  4. Compile error

The correct option is (a).

Explanation:

In a statement printf("%u %s\n", &"Welcome", &"Programming");

The %u format specifier tells the compiler to print the memory address of the "Welcome".

The %s format specifier tells the compiler to print the string "Programming".

Hence the output of the program is "2022 Programming".





Latest Courses