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
main()
{
	char *p1="Name";
	char *p2;
	p2=(char *)malloc(20);
	while(*p2++=*p1++);
	printf("%s\n",p2);
}
what is the output?



 Question Submitted By :: Naveed
I also faced this Question!!     Rank Answer Posted By  
 
  Re: main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } what is the output?
Answer
# 1
name
 
Is This Answer Correct ?    0 Yes 0 No
Mannucse
[Kiona]
 
  Re: main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } what is the output?
Answer
# 2
ANS: NULL
It is a bit tricky question. If u observe carefully then we
are incrementing the pointers p1,p2. When it reached the end
of the string, *p2 points to NULL. We have lost the address
of the starting position.
 
Is This Answer Correct ?    0 Yes 0 No
Sanath
 
 
 
  Re: main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } what is the output?
Answer
# 3
-> while(*p2++ "=" *p1++)
the syntax of while is 
  while("condition");

in condition statement the assignment operator is used in a 
wrong way..
when we are using loop it should be "=="..

we cannot copy the value of p1 in p2, the way its mentioned 
here..


** It will either give an error or display some garbage 
value in p2 , or no value..
depends on what p2 is initialised to implicitly..
 
Is This Answer Correct ?    0 Yes 0 No
Shruti
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?  1
logic for generating all the combinations of the any number of given letters. ex::::::::: if a,b,c,d are given the o/p should be abcd,dcba,dbac,bcad,................ 4*3*2*1 combinations............ Infosys1
find the output of the following program main() { int x=5, *p; p=&x; printf("%d",++*p); } TCS4
4.A function 'q' that accepts a pointer to a character as argument and returns a pointer to an array of integer can be declared as: A)int (*q(char*)) [] B)int *q(char*) [] C)int(*q)(char*) [] D)None of the Above Accenture4
program to find the ASCII value of a number  5
What is structure packing ? HP1
Struct(s) { int a; long b; } Union (u) {int a; long b; } Print sizeof(s)and sizeof(u) if sizeof(int)=4 and sizeof(long)=4 Mascot2
Concat two string with most overlapped substring has to remove  "abcd"+ "cdef" = "abcdef  5
what is the differance between pass by reference and pass by value. Infosys4
how to find the size of the data type like int,float without using the sizeof operator?  5
Convert the following expression to postfix and prefix (A+B) * (D-C)  1
x=2,y=6,z=6 x=y==z; printf(%d",x) HCL7
write a fuction for accepting and replacing lowercase letter to'Z' with out using inline function. Temenos3
what is use#in c  2
main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } what is the output? Ramco3
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it?  2
1.write a program to merge the arrays 2.write efficient code for extracting unique elements from a sorted list of array? Qualcomm1
int a=2,b=3,c=4; printf("a=%d,b=%d\n",a,b,c); what is the o/p? Verifone4
What's wrong with "char *p = malloc(10);" ?  4
How the processor registers can be used in C ? HP4
 
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