edited by
6,037 views
1 votes
1 votes

The following is a C code-

int main(void)
{
    char buff[10];
    memset(buff,0,sizeof(buff));
    gets(buff);
    printf(" The buffer entered is [%s] ",buff);
    return 0;
}

(A) The program assigns a memory area to buff successfully and works fine.

(B) The program may not compile properly.

(C) The program is compiled  but it may lead to buffer over overflow sometimes.

(D) The program has no issue

edited by

1 Answer

1 votes
1 votes
The problem with the code above is the use of the function gets(). This function accepts a string from stdin without checking the capacity of buffer in which it copies the value. This may well result in buffer overflow. The standard function fgets() is advisable to use in these cases.

Therefore option C is correct

Related questions