Which of these functions is safer to use : fgets(), gets()? Why?



Which of these functions is safer to use : fgets(), gets()? Why?..

Answer / Gaurav Mishra

fgets() is safer to use compared to gets(). The primary reason is that fgets() allows you to specify the maximum number of characters to read, preventing potential buffer overflows. On the other hand, gets() reads an entire line from stdin without a size limit, which can result in unintended consequences when used improperly.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

what is the output of the following program? #include<stdio.h> void main() { float x=1.1; while(x==1.1) { printf("\n%f",x); x=x-0.1; } }

6 Answers  


Explain how do you use a pointer to a function?

1 Answers  


What is difference between structure and union?

1 Answers  


what is the c source code for the below output? 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1

0 Answers  


how does the C compiler interpret the following two statements p=p+x; q=q+y; a. p=p+x; q=q+y b. p=p+xq=q+y c. p=p+xq; q=q+y d. p=p+x/q=q+y

2 Answers   TCS, Tech Synergy,


What is an lvalue and an rvalue?

1 Answers  


How does placing some code lines between the comment symbol help in debugging the code?

1 Answers  


What is false about the following A compound statement is a.A set of simple statments b.Demarcated on either side by curly brackets c.Can be used in place of simple statement d.A C function is not a compound statement.

5 Answers   CCEM, TCS,


How do you list a file’s date and time?

1 Answers  


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

1 Answers   Mind Tree,


the maximum width of a c variable name can be a) 6 characters b) 8 characters c) 10 characters d) 20 characters

2 Answers  


What is #include in c?

1 Answers  


Categories