Input and Output
Predict 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; } |
9
| |
1
| |
10
| |
100
|
Question 1 Explanation:
scanf returns the no. of inputs it has successfully read. Seehttp://geeksforgeeks.org/archives/674
Question 3
WRONG
|
#include <stdio.h> int main() { printf ( " \"GEEKS %% FOR %% GEEKS\"" ); getchar (); return 0; } |
“GEEKS % FOR % GEEKS”
| |
GEEKS % FOR % GEEKS
| |
\"GEEKS %% FOR %% GEEKS\"
| |
GEEKS %% FOR %% GEEKS
|
Predict the output of the below program:
#include <stdio.h> int main() { printf ( "%c " , 5[ "GeeksQuiz" ]); return 0; } |
Compile-time error
| |
Runtime error
| |
Q
| |
s
|
Discuss it
Question 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 6
WRONG
|
Predict the output of below program:
#include <stdio.h> int main() { printf ( "%c " , "GeeksQuiz" [5]); return 0; } |
Compile-time error
| |
Runtime error
| |
Q
| |
s
|
Discuss it
Question 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 8
WRONG
|
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
|
Discuss it
Question 9
CORRECT
|
What does the following C statement mean?
scanf ( "%4s" , str); |
Read exactly 4 characters from console.
| |
Read maximum 4 characters from console.
| |
Read a string str in multiples of 4
| |
Nothing
|
Discuss it
Question 9 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; }
Question 10
WRONG
|
#include<stdio.h> int main() { char *s = "Geeks Quiz" ; int n = 7; printf ( "%.*s" , n, s); return 0; } |
Geeks Quiz
| |
Nothing is printed
| |
Geeks Q
| |
Geeks Qu
|
Discuss it
Question 10 Explanation:
.* means The precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.
#include<stdio.h> int main() { printf ( "%d" , printf ( "%d" , 1234)); return 0; } |
12344
| |
12341
| |
11234
| |
41234
|
Discuss it
Question 12 Explanation:
printf() returns the number of characters successfully printed on the screen.
Question 14
CORRECT
|
Normally user programs are prevented from handling I/O directly by I/O instructions in them. For CPUs having explicit I/O instructions, such I/O protection is ensured by having the I/O instructions privileged. In a CPU with memory mapped I/O, there is no explicit I/O instruction. Which one of the following is true for a CPU with memory mapped I/O?
I/O protection is ensured by operating system routine (s)
| |
I/O protection is ensured by a hardware trap
| |
I/O protection is ensured during system configuration
| |
I/O protection is not possible
|
Discuss it
Question 14 Explanation:
User applications are not allowed to perform I/O in user mode - All I/O requests are handled through system calls that must be performed in kernel mode.
xanda
No comments:
Post a Comment