Exams › GATE › Technical
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?
- The function call fX("abcd") will always return a value
- Assuming a character array c is declared as char c[] = "abcd" in main(), the function call fX(c) will always return a value
- The code of the function will not compile
- 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
- Which of the following statements about the Two Phase Locking (2PL) protocol is/are TRUE?
- Which of the following fields of an IP header is/are always modified by any router before it forwards the IP packet?
- The three-dimensional state of stress at a point is given by σ = [[10, 0, 0],[0, 40, 0],[0, 0, 0]] MPa. The maximum shear stress at the point is
- A 2 m wide strip footing is founded at a depth of 1.5 m below the ground level in a homogeneous pure clay bed. The clay bed has unit cohesion of 40 kPa. Due to seasonal fluctuations of water table from peak summer to peak monsoon period, the net ultimate bearing capacity of the footing, as per Terzaghi’s theory, will
- Consider the statements P and Q.
P: Soil particles formed by mechanical weathering, and close to their origin are generally subrounded.
Q: A activity of the clay physically signifies its swell potential.
Which one of the following options is CORRECT?
- The number of degrees of freedom for a natural open channel flow with a mobile bed is
⚔️ Practice GATE Technical free + battle 1v1 →