The Gateway to Computer Science Excellence
+1 vote
88 views

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

in Programming by Boss (17.6k points)
edited by | 88 views

1 Answer

+1 vote
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
by Active (1.7k points)
0
your answer is correct but logic is incorrect.
0
Then please explain me the logic
0

@sushmita explain logic

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,291 answers
198,211 comments
104,903 users