Exercise: Questions on Input and Output


Questions on Input and Output : Question 1 :
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 "PROcoder" */
     return 1;
 }
 

9
1
10
100
Show Answer
Questions on Input and Output : Question 2 :
Predict output of the following program
  
        #include <stdio.h>  
        int main()  
        {     
            printf("\new_c_question\by");     
            printf("\rprocoder");      
            getchar();     
            return 0;  
        }  
    

ew_c_question
procoder
new_c_ques
procoder

procoder
Depends on terminal configuration
Show Answer
Questions on Input and Output : Question 3 :
 #include <stdio.h>
 
 int main() 
 { 
   printf(" \"PRO %% CO %% DER\""); 
   getchar(); 
   return 0; 
 }

"PRO % CO % DER"
PRO % CO % DER
\"PRO %% CO %% DER\"
PRO %% CO %% DER
Show Answer
Questions on Input and Output : Question 4 :
 #include <stdio.h>
 // Assume base address of "PROcoder" to be 1000
 int main()
 {
    printf(5 + "PROcoder");
    return 0;
 }
 

PROcoder
der
1005
Compile-time error
Show Answer
Questions on Input and Output : Question 5 :
Predict the output of the below program:
 #include <stdio.h>
 
 int main()
 {
     printf("%c ", 5["PROcoder"]);
     return 0;
 }
 

Compile-time error
Runtime error
d
o
Show Answer
Questions on Input and Output : Question 6 :
Predict the output of below program:
 #include <stdio.h>
 int main()
 {
     printf("%c ", "PROcoder"[5]);
     return 0;
 }
 

Compile-time error
Runtime error
d
o
Show Answer
Questions on Input and Output : Question 7 :
Which of the following is true

gets() can read a string with newline chacters 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 above
Show Answer
Questions on Input and Output : Question 8 :
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
Show Answer
Questions on Input and Output : Question 9 :
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
Show Answer
Questions on Input and Output : Question 10 :
 #include<stdio.h>
 
 int main()
 {
     char *s = "PRO coder";
     int n = 7;
     printf("%.*s", n, s);
     return 0;
 }
 

PRO coder
Nothing is printed
PRO cod
PRO code
Show Answer