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                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
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
write a C program to print the program itself ?!
 Question Submitted By :: PK
I also faced this Question!!     Rank Answer Posted By  
 
  Re: write a C program to print the program itself ?!
Answer
# 1
#include<stdio.h>
#include<conio.h>
void main()
{
  clrscr();
  printf("hai");
 getch();
}
 
Is This Answer Correct ?    0 Yes 9 No
Abiraj1030&yahoo.com
 
  Re: write a C program to print the program itself ?!
Answer
# 2
#include<iostream.h>
#include<conio.hg>
int main()
{
clrscr();
printf(" \t  hi this is sriram \t \n");
getch();
return 0;
}
 
Is This Answer Correct ?    0 Yes 7 No
Sriram
 
 
 
  Re: write a C program to print the program itself ?!
Answer
# 3
this can be achieved by file handling

#include<stdio.h>
void main()
{
FILE *fp;
char ch;
clrscr();
fp=fopen("file.c","r");
ch=getc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=getc(fp);
}
getch();
}
 
Is This Answer Correct ?    4 Yes 1 No
Vinay Tiwari
 
  Re: write a C program to print the program itself ?!
Answer
# 4
The most simple possible program printing itself on windows :
main()
{
char path[255];
sprintf(path,"cmd.exe /c type \"%s\"",__FILE__);
system(path);
}

on Unix you just use "cat" instead of "type" and necessary
fun to call bash command from c program.
 
Is This Answer Correct ?    2 Yes 1 No
Jaroosh
 
  Re: write a C program to print the program itself ?!
Answer
# 5
This can be achieved by file handling,
If r is the name of this file;The following codewil print 
this prg.

#include<stdio.h>
void main()
{
FILE *fp;
char ch;
clrscr();
fp=fopen("file.c","r");
ch=getc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=getc(fp);
}
getch();
}
 
Is This Answer Correct ?    4 Yes 1 No
Vikraman85
[Anna University!]
 
  Re: write a C program to print the program itself ?!
Answer
# 6
main(a){printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34);}

copied from somewhere, but it works
 
Is This Answer Correct ?    1 Yes 2 No
Yang
 
  Re: write a C program to print the program itself ?!
Answer
# 7
#include<stdio.h>

char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}";
main()
{
printf(s,34,s,34);
}
 
Is This Answer Correct ?    1 Yes 0 No
Manish
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
int a=1,b=2,c=3; printf("%d,%d",a,b,c); What is the output? Verifone11
what is meant by c  4
Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 1. Print only the alphabets . If in upper case print in lower case vice versa.  1
what is differnence b/w macro & functions  1
How can I get Single byte from 'int' type variable? Can we alter single bit or multiple bits in int type variable? if so, How?  1
what are the uses of structure? HCL3
enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); } ME2
main() { int a=0; if(a=0) printf("Ramco Systems\n"); printf("India\n"); } output? Ramco6
I have a function which accepts a pointer to an int. How can I pass a constant like 5 to it?  3
AMMONG THE 4 STROAGE CLASSES IN C, WHICH ONE FASTEST? HCL9
Explain what?s happening in the first constructor: public class c{ public c(string a) : this() {;}; public c() {;} } How is this construct useful?  1
pgm to find middle element of linklist(in efficent manner) Huawei1
What is false about the following A compound statement is a.A set of simple statments b.Demarcated on either side by curly brackets c.Can be used in place of simple statement d.A C function is not a compound statement. TCS1
WAP TO ACCEPT STRING AND COUNT A COMES N TIMES B COMES N TIMES C COMES N TIMES D COMES N TIMES AND SO ON......... AT LAST UNTIL Z COMES N TIMES...............  2
how to print "hai" in c?  9
fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? } NDS12
#define d 10+10 main() { printf("%d",d*d); }  2
Write a program that takes three variables(a,b,c) in as separate parameters and rotates the values stored so that value a goes to b,b,to c and c to a  2
a C prog to swap 2 no.s without using variables just an array? TCS4
How to reverse a string using a recursive function, without swapping or using an extra memory? Motorola15
 
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