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 ?    5 Yes 32 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 ?    2 Yes 29 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 ?    21 Yes 7 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 ?    9 Yes 5 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 ?    11 Yes 9 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 ?    8 Yes 9 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 ?    8 Yes 6 No
Manish
 
  Re: write a C program to print the program itself ?!
Answer
# 8
#include <stdio.h>

int main()
{
  char a[] = "int main(){char a[] = %c%s%c; char b = '%c'; printf(a,b,a,b,b);}";
  char b = '"';

  printf(a,b,a,b,b);
}
 
Is This Answer Correct ?    2 Yes 4 No
Joyab
 
  Re: write a C program to print the program itself ?!
Answer
# 9
#include<fstream>
void main()
{
	std::ifstream is(__FILE__);

	while(!is.eof())
		printf("%c", is.get());

	is.close();
}
 
Is This Answer Correct ?    2 Yes 1 No
Hillel
 
  Re: write a C program to print the program itself ?!
Answer
# 10
#include<stdio.h>
#include<conio.h>


int  main()
{
	FILE *fin;
	char c;
	fin=fopen("prntsrccode.c","r");
	if(fin==NULL)
	{
		printf("Error Opening file in read mode");
		exit(1);
	}
	do
	{
		c=fgetc(fin);
		fputchar(c);
	}while(c!=EOF);

	fclose(fin);

	getch();
	return 0;
}
 
Is This Answer Correct ?    0 Yes 2 No
Mobashyr
 
  Re: write a C program to print the program itself ?!
Answer
# 11
#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 0 No
Abhishek
 
  Re: write a C program to print the program itself ?!
Answer
# 12
Most simplest ....

char *p="char *p=%s int main(){ printf(p,p);getchar();}";int
main(){ printf(p,p);getchar();}
 
Is This Answer Correct ?    0 Yes 0 No
Vara
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
write a program to compare 2 numbers without using logical operators? IBM1
what are the various memory handling mechanisms in C ? HP3
what is volatile in c language? TCS1
What is the memory allocated by the following definition ? int (*x)[10]; ADITI3
can i know the source code for reversing a linked list with out using a temporary variable? Honeywell6
34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?  2
How can I allocate arrays or structures bigger than 64K?  4
for example user gives input as " 20 or 20.0 or rs 20.0 or 20.00 or rs20 and so .. on " and the output should be stored as " rs.20.00 " in a variable  2
Concat two string with most overlapped substring has to remove  "abcd"+ "cdef" = "abcdef  5
What is #pragma directive?how it is used in the program? what is its advantages and disadvantages?  1
#include<stdio.h> main() { char *p1; char *p2; p1=(char *) malloc(25); p2=(char *) malloc(25); strcpy(p1,"Ramco"); strcpy(p2,"Systems"); strcat(p1,p2); printf("%s",p1); } Tell me the output? Ramco5
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
What is meant by global static? why we have to use static variable instead of Global variable L&T2
Look at the Code: main() { int a[]={1,2,3},i; for(i=0;i<3;i++) { printf("%d",*a); a++; } } Which Statement is/are True w.r.t the above code? I.Executes Successfully & Prints the contents of the array II.Gives the Error:Lvalue Required III.The address of the array should not be changed IV.None of the Above. A)Only I B)Only II C)II & III D)IV Accenture3
c programming of binary addition of two binary numbers  1
How would you find a cycle in a linked list?  2
What will be printed as the result of the operation below: #include<..> int x; int modifyvalue() { return(x+=10); } int changevalue(int x) { return(x+=1); } void main() { int x=10; x++; changevalue(x); x++; modifyvalue(); printf("First output:%d\n",x); x++; changevalue(x); printf("Second output:%d\n",x); modifyvalue(); printf("Third output:%d\n",x); }  2
wats SIZE_T meant for?  1
Write a C program to print 1 2 3 ... 100 without using loops?  5
Write a program to find the smallest and largest element in a given array in c language Microsoft3
 
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