Which of the following is true
(A) gets() can read a string with newline characters but a normal scanf() with %s can not.
(B) gets() can read a string with spaces but a normal scanf() with %s can not.
(C) gets() can always replace scanf() without any additional code.
(D) None of the above
Answer: (B)
Explanation: gets() can read a string with spaces but a normal scanf() with %s can not. Consider following program as an example.
If we enter “Geeks Quiz” as input in below program, the program prints “Geeks”
int main()
{
char str[100];
scanf ( "%s" , str);
printf ( "%s" , str);
}
|
But in the following program, if we enter “Geeks Quiz”, it prints “Geeks Quiz”
int main()
{
char str[100];
gets (str);
printf ( "%s" , str);
}
|
Quiz of this Question
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
31 Aug, 2021
Like Article
Save Article