Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NETUncategorized

C Programming Questions and Answers – Standard Input & Output

C Programming Questions and Answers – Standard Input & Output

 

1.Which among the following is odd one out?

a) printf

b) fprintf

c) putchar

d) scanf

View Answer

Answer:d 

2.For a typical program, the input is taken using

a) scanf

b) Files

c) Command-line

d) All of the mentioned

View Answer

Answer:d  

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

View Answer

Answer:c 

4.What is the default return-type of getchar()?

a) char

b) int

char *

Reading character doesn’t require a return-type

View Answer

Answer:b 

5.The value of EOF is_____

a) -1

b) 0

c) 1

d) 10

View Answer

Answer:a 

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) Both a & b

d) None of the mentioned

View Answer

Answer:c   

7.Which is true?

a) The symbolic constant EOF is defined in <stdio.h>

b) The value is -1

c) Both a & b

d) Only b

View Answer

Answer:c  

8.What is the return value of putchar()?

a) The character written

b) EOF if an error occurs

c) Nothing

d) Both a & b

View Answer

Answer:d   

9.Which is true about function tolower?

a) The function tolower is defined in

b) Converts an upper case letter to lower case

c) returns other characters untouched

d) None of the mentioned

View Answer

Answer:d   

10.What is the output of this C code?

#include <stdio.h>

int main()

{

char c = ‘?’;

putchar(c);

}

a) Compile time error

b) Nothing

c) 0

d) Undefined behaviour

View Answer

Answer:b 

11.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

View Answer

Answer:b

12.What is the output of this 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

View Answer

Answer:c 

13.What is the output of this 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

View Answer

Answer:b

14.What is the output of this 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

View Answer

Answer:b 

15.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

View Answer

Answer:a 

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button