C Input and Output Last Updated : 28 Sep, 2023 C Input and Output Please wait while the activity loads. If this activity does not load, try refreshing your browser. Also, this page requires javascript. Please visit using a browser with javascript enabled. If loading fails, click here to try again Question 1Predict the output of following program? #include "stdio.h" int main() { char arr[100]; printf("%d", scanf("%s", arr)); /* Suppose that input value given for above scanf is "GeeksQuiz" */ return 1; } 9110100C Input and Output Discuss itQuestion 1-Explanation: In C, scanf returns the no. of inputs it has successfully read. See http://geeksforgeeks.org/archives/674Question 2 Predict output of the following program C #include <stdio.h> int main() { printf("new_c_questionbr"); printf("geeksforgeeks"); getchar(); return 0; } ew_c_questiongeeksforgeeks new_c_quesgeeksforgeeks geeksforgeeks Depends on terminal configuration C Input and Output C++ Constructors Discuss itQuestion 2-Explanation: See https://stackoverflow.com/questions/17236242/usage-of-b-and-r-in-c/%22 Question 3 #include <stdio.h> int main() { printf(" \"GEEKS %% FOR %% GEEKS\""); getchar(); return 0; }“GEEKS % FOR % GEEKS”GEEKS % FOR % GEEKS \\\"GEEKS %% FOR %% GEEKS\\\"GEEKS %% FOR %% GEEKSC Input and Output Discuss itQuestion 3-Explanation: Backslash (\\\\\\\\) works as escape character for double quote (“). For explanation of %%, see http://www.geeksforgeeks.org/how-to-print-using-printf/Question 4 C #include <stdio.h> // Assume base address of "GeeksQuiz" to be 1000 int main() { printf(5 + "GeeksQuiz"); return 0; } GeeksQuiz Quiz 1005 Compile-time error C Input and Output 50 C Language MCQs with Answers Discuss itQuestion 4-Explanation: printf is a library function defined under stdio.h header file. The compiler adds 5 to the base address of the string through the expression 5 + \"GeeksQuiz\" . Then the string \"Quiz\" gets passed to the standard library function as an argument. Question 5 Predict the output of the below program: C #include <stdio.h> int main() { printf("%c ", 5["GeeksQuiz"]); return 0; } Compile-time error Runtime error Q s C Input and Output Discuss itQuestion 5-Explanation: The crux of the program lies in the expression: 5[\"GeeksQuiz\"] This expression is broken down by the compiler as: *(5 + \"GeeksQuiz\"). Adding 5 to the base address of the string increments the pointer(lets say a pointer was pointing to the start(G) of the string initially) to point to Q. Applying value-of operator gives the character at the location pointed to by the pointer i.e. Q. Question 6Predict the output of below program: #include <stdio.h> int main() { printf("%c ", "GeeksQuiz"[5]); return 0; } Compile-time errorRuntime errorQsC Input and Output Discuss itQuestion 6-Explanation: The crux of the program lies in the expression: \"GeeksQuiz\"[5]. This expression is broken down by the compiler as: *(“GeeksQuiz” + 5). Adding 5 to the base address of the string increments the pointer(lets say a pointer was pointing to the start(G) of the string initially) to point to Q. Applying value-of operator gives the character at the location pointed to by the pointer i.e. Q.Question 7 When a copy constructor may be called? When an object of the class is returned by value.When an object of the class is passed (to a function) by value as an argument. When an object is constructed based on another object of the same classWhen compiler generates a temporary object.All of the aboveC++ Constructors C Input and Output Discuss itQuestion 7-Explanation: All the given options are correct as copy constructor can be called in any of the situation. Question 8Which of the following is truegets() can read a string with newline characters but a normal scanf() with %s can not.gets() can read a string with spaces but a normal scanf() with %s can not.gets() can always replace scanf() without any additional code.None of the aboveC Input and Output Discuss itQuestion 8-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\" But in the following program, if we enter \"Geeks Quiz\", it prints \"Geeks Quiz\" Question 9 Which of the following is true? gets() doesn\'t do any array bound testing and should not be used. fgets() should be used in place of gets() only for files, otherwise gets() is fine gets() cannot read strings with spaces None of the above C Input and Output 50 C Language MCQs with Answers Discuss itQuestion 9-Explanation: Use of gets() generates the risk of an overflow of the allocated buffer. This happens because the function gets(), doesn\'t know the size of the buffer, and continues reading until it finds a newline \"\\n\" or encounters EOF, and so it may overflow the bounds of the buffer it was given. See gets() is risky to use! Question 10 What does the following C statement mean? C scanf("%4s", str); Read exactly 4 characters from console. Read maximum 4 characters from console. Read a string str in multiples of 4 Nothing C Input and Output 50 C Language MCQs with Answers Discuss itQuestion 10-Explanation: Try following program, enter GeeksQuiz, the output would be \"Geek\" #include <stdio.h> int main() { char str[50] = {0}; scanf(\"%4s\", str); printf(str); getchar(); return 0; } 1234 There are 37 questions to complete. You have completed questions question Your accuracy is Correct Wrong Partial-Credit You have not finished your quiz. If you leave this page, your progress will be lost. Correct Answer You Selected Not Attempted Final Score on Quiz Attempted Questions Correct Attempted Questions Wrong Questions Not Attempted Total Questions on Quiz Question Details Results Date Score Hint Time allowed minutes seconds Time used Answer Choice(s) Selected Question Text Need more practice! Keep trying! Not bad! Good work! Perfect! Share your thoughts in the comments Add Your Comment Please Login to comment...