top of page
Writer's pictureApurba Paul

C Operators & Expressions_4: Input and Output

Basic Input and Output in C:

please find the below link:


Questions on Input Output:

1. Which among the following is the odd one out? a) printf b) fprintf c) putchar d) scanf

2. For a typical program, the input is taken using _________ a) scanf b) Files c) Command-line d) All of the mentioned

3. What does the following command line signify?

prog1|prog2

a) It runs prog1 first, prog2 second b) It runs prog2 first, prog1 second c) It runs both the programs, pipes output of prog1 to input of prog2 d) It runs both the programs, pipes output of prog2 to input of prog1

4. What is the default return-type of getchar()? a) char b) int c) char * d) reading character doesn’t require a return-type

5. What is the value of EOF? a) -1 b) 0 c) 1 d) 10

6. What is the use of getchar()? a) The next input character each time it is called b) EOF when it encounters end of file c) The next input character each time it is called EOF when it encounters end of file d) None of the mentioned

7. Which of the following statement is true? a) The symbolic constant EOF is defined in <stdio.h> b) The value is -1 c) The symbolic constant EOF is defined in <stdio.h> & value is -1 d) Only value is -1

8. What is the return value of putchar()? a) The character written b) EOF if an error occurs c) Nothing d) Both character written & EOF if an error occurs


1. Which is true about function tolower? a) The function tolower is defined in <ctype.h> b) Converts an uppercase letter to lowercase c) Returns other characters untouched d) None of the mentioned

2. What will be the output of the following C code?

   #include <stdio.h>
   int main()
   {
       char c = '�';
       putchar(c);
   }

a) Compile time error b) Nothing c) 0 d) Undefined behaviour

3. putchar(c) function/macro always outputs character c to the __________ a) screen b) standard output c) depends on the compiler d) depends on the standard

4. What will be the output of the following C code if following commands are used to run (considering myfile exists)?

   gcc -otest test.c
   ./test < myfile
 
   #include <stdio.h>
   int main()
   {
       char c = 'd';
       putchar(c);
   }

a) Compile time error (after first command) b) d in the myfile file c) d on the screen d) Undefined behaviour

5. What will be the output of the following C code if following commands are used to run (considering myfile exists)?

   gcc -otest test.c
   ./test > myfile
 
    #include <stdio.h>
   int main(int argc, char **argv)
   {
       char c = 'd';
       putchar(c);
       printf(" %d\n", argc);
   }

a) d 2 in myfile b) d 1 in myfile c) d in myfile and 1 in screen d) d in myfile and 2 in screen

6. What will be the output of the following C code if following commands are used to run and if myfile does not exist?


   gcc -o test test.c
   ./test > myfile
 
   #include <stdio.h>
   int main(int argc, char **argv)
   {
       char c = 'd';
       putchar(c);
       printf(" %d\n", argc);
   }

a) d 2 in myfile b) d 1 in myfile c) Depends on the system d) Depends on the standard

7. The statement prog < infile causes _________ a) prog to read characters from infile b) prog to write characters to infile c) infile to read characters from prog instead d) nothing


1. Which is true about function tolower? a) The function tolower is defined in <ctype.h> b) Converts an uppercase letter to lowercase c) Returns other characters untouched d) None of the mentioned

2. What will be the output of the following C code?

   #include <stdio.h>
   int main()
   {
       char c = '�';
       putchar(c);
   }

a) Compile time error b) Nothing c) 0 d) Undefined behaviour

3. putchar(c) function/macro always outputs character c to the __________ a) screen b) standard output c) depends on the compiler d) depends on the standard

4. What will be the output of the following C code if following commands are used to run (considering myfile exists)?

   gcc -otest test.c
   ./test < myfile
 
   #include <stdio.h>
   int main()
   {
       char c = 'd';
       putchar(c);
   }

a) Compile time error (after first command) b) d in the myfile file c) d on the screen d) Undefined behaviour

5. What will be the output of the following C code if following commands are used to run (considering myfile exists)?

   gcc -otest test.c
   ./test > myfile
 
    #include <stdio.h>
   int main(int argc, char **argv)
   {
       char c = 'd';
       putchar(c);
       printf(" %d\n", argc);
   }

a) d 2 in myfile b) d 1 in myfile c) d in myfile and 1 in screen d) d in myfile and 2 in screen

6. What will be the output of the following C code if following commands are used to run and if myfile does not exist?

advertisement

   gcc -o test test.c
   ./test > myfile
 
   #include <stdio.h>
   int main(int argc, char **argv)
   {
       char c = 'd';
       putchar(c);
       printf(" %d\n", argc);
   }

a) d 2 in myfile b) d 1 in myfile c) Depends on the system d) Depends on the standard

7. The statement prog < infile causes _________ a) prog to read characters from infile b) prog to write characters to infile c) infile to read characters from prog instead d) nothing


1. What is the meaning of the following C statement?

printf(“%10s”, state); 

a) 10 spaces before the string state is printed b) Print empty spaces if the string state is less than 10 characters c) Print the last 10 characters of the string d) None of the mentioned

2. What are the Properties of the first argument of a printf() functions? a) It is defined by a user b) It keeps the record of the types of arguments that will follow c) There may no be first argument d) None of the mentioned

3. What will be the output of the following C code?

   #include <stdio.h>
   int main()
   {
       int i = 10, j = 2;
       printf("%d\n", printf("%d %d ", i, j));
   }

a) Compile time error b) 10 2 4 c) 10 2 2 d) 10 2 5

4. What will be the output of the following C code?

   #include <stdio.h>
   int main()
   {
       int i = 10, j = 3;
       printf("%d %d %d", i, j);
   }

a) Compile time error b) 10 3 c) 10 3 some garbage value d) Undefined behaviour

5. What will be the output of the following C code?

   #include <stdio.h>
   int main()
   {
       int i = 10, j = 3, k = 3;
       printf("%d %d ", i, j, k);
   }

a) Compile time error b) 10 3 3 c) 10 3 d) 10 3 some garbage value

6. What will be the output of the following C code?

   #include <stdio.h>
   int main()
   {
       char *s = "myworld";
       int i = 9;
       printf("%*s", i, s);
   }

a) myworld b) myworld(note: spaces to the left of myworld) c) myworld (note:followed by two spaces after myworld) d) Undefined

7. What will be the output of the following C code?

   #include <stdio.h>
   int main(int argc, char **argv)
   {
       char *s = "myworld";
       int i = 3;
       printf("%10.*s", i, s);
   }

a) myw b) myworld(note:2 spaces before myworld) c) myworld (note:2 spaces after myworld) d) myw(note:6 spaces after myworld)

8. What is the difference between %e and %g? a) %e output formatting depends on the argument and %g always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional b) %e always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional and output formatting depends on the argument c) No differences d) Depends on the standard

34 views0 comments

Recent Posts

See All

Comentários


bottom of page