StreakPeaked· Practice

ExamsGATETechnical

Consider the following C function definition. int fX(char *a){ char *b = a; while (*b) b++; return b - a;} Which of the following statements is/are TRUE?

  1. The function call fX("abcd") will always return a value
  2. Assuming a character array c is declared as char c[] = "abcd" in main(), the function call fX(c) will always return a value
  3. The code of the function will not compile
  4. Assuming a character pointer c is declared as char *c = "abcd" in main(), the function call fX(c) will always return a value

Correct answer: The function call fX("abcd") will always return a value

Solution

The function fX counts the number of characters in the string pointed to by 'a' by iterating through it until it reaches the null terminator. Since the input '"abcd"' is a valid string, the function will successfully return the length of the string, which is always a value.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →