ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
How do you write a program which produces its own source
code as its output?
 Question Submitted By :: Tribhuvan Sharma
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How do you write a program which produces its own source code as its output?
Answer
# 1
printitself.c

#include <stdio.h>

int main()
{

char ch;
FILE *file;

file=fopen("printitself.c","r");

while((ch=fgetc(file))!=EOF)
printf("%c",ch);

return 0;
}
 
Is This Answer Correct ?    4 Yes 0 No
Vivek
 
  Re: How do you write a program which produces its own source code as its output?
Answer
# 2
Try to google....quine Problem...

one solution is 

main(){char *c="main(){char
*c=%c%s%c;printf(c,34,c,34);}";printf(c,34,c,34);}
 
Is This Answer Correct ?    1 Yes 0 No
Abhinav Gupta
 
 
 
  Re: How do you write a program which produces its own source code as its output?
Answer
# 3
#include <stdio.h>

static char prog[] = "#include <stdio.h>%c%cstatic char prog[] = %c%s%c;%c%cint main(void)%c{%c    printf(prog, 10, 10, 34, prog, 34, 10, 10, 10, 10, 10, 10, 10);%c    return 0;%c}%c";

int main(void)
{
    printf(prog, 10, 10, 34, prog, 34, 10, 10, 10, 10, 10, 10, 10);
    return 0;
}
 
Is This Answer Correct ?    0 Yes 1 No
Abhishek
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
how to sort two array of characters and make a new array of characters. Accenture1
WHAT IS THE DIFFERANCE BITWIN GETS();AND SCANF();  2
How the C program can be compiled? HP7
Print all numbers which has a certain digit in a certain position eg: number=45687 1 number=4 2 number=5 etc  2
Why preprocessor should come before source code?  2
we have to use realloc only after malloc or calloc ? or we can use initially with out depending on whether we are using malloc or calloc in our program ?  1
What is structure padding & expalain wid example what is bit wise structure?  1
5. What kind of sorting is this: SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort Accenture2
write an algorithm which can find the largest number among the given list using binary search ............... this was asked in the interview Satyam2
Given an unsigned integer, find if the number is power of 2?  4
main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); } what is the output? Ramco7
difference between i++* and *++i IBM3
Identify the correct argument for the function call fflush () in ANSI C: A)stdout B)stdin C)stderr D)All the above Accenture3
Study the Following Points: a.One Cannot Take the address of a Bit Field b.bit fields cannot be arrayed c.Bit-Fields are machine Dependant d.Bit-fields cannot be declared as static 1. Which of the Following Statements are true w.r.t Bit- Fields A)a,b&c B)Only a & b C)Only c D)All Accenture2
write a 'c' program to sum the number of integer values  5
What is RAM memory? and What is ROM?Who designed one is temparary and another is permanent?why they designed like that?By using far pointer which type data(whether hexadecimal)we can access? Excel1
if the address of a[1,1] and a[2,1] are 1000 and 1010 respectively and each occupies 2 bytes then the array has been stored in what order?  3
if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')  9
difference between my-strcpy and strcpy ? Geometric-Software3
#include <stdio.h> #define sqr(x) (x*x) int main() { int x=2; printf("value of x=%d",sqr(x+1)); } What is the value of x? Oracle13
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com