in Programming in C
617 views
0 votes
0 votes
  • P1: A program can print its source code once.
  • P2: A program can print its source code twice.
  • P3: A program takes an input n and prints its source code n number of times.

Which of these programs are possible in C++/Java without the use of File I/O ?

Options:

A. P1 possible
B. P1 and P2 possible.
C. None Possible.
D. All are possible

Option can be different

in Programming in C
617 views

3 Answers

3 votes
3 votes
Best answer

First you should notice that File Input/Output is not allowed. If its allowed then option (D) would be the correct answer. But as its not allowed hence it will not be the answer.

Correct answer is (B). Here is the explanation. A computer program which print it's own source code is called quine.

quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output. The standard terms for these programs in the computability theory and computer science literature are "self-replicating programs", "self-reproducing programs", and "self-copying programs".

It can print twice or thrice. But number of times should be fixed. It can not take input from user. Hence P3 will not be possible. 

selected by
by

1 comment

It make sense...  :)
0
0
0 votes
0 votes
The question does not make any sense due to options :O

To print the content of the program we have the macro __FILE__ in C/C++ and this returns the source code as a string. So, all options should be true.
by

3 Comments

The question was like..
Which of the programs are possible without accessing the source code file of the program?

Can you explain which topic is this from? I completely dint understand this question :(
0
0
Wheather the question  made sense or not.

I had completely no idea what the question was about....
0
0
@Arjun Sir can you read my answer? Please verify it.
0
0
0 votes
0 votes
Option D is correct

Related questions