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                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
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
f(char *p)
 {
 p=(char *)malloc(sizeof(6));
strcpy(p,"HELLO");
}
main()
{
 char *p="BYE";
 f(p)
printf("%s",p);
}
what is the output?
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: f(char *p) { p=(char *)malloc(sizeof(6)); strcpy(p,"HELLO"); } main() { char *p="BYE"; f(p) printf("%s",p); } what is the output?
Answer
# 1
the outpu is hello coz the pointer is pointing to a 
location where the string "bye" is written in the next 
program yu are using the same pointer to point to some 
other string so it gets overwritten
 
Is This Answer Correct ?    0 Yes 1 No
Deepa
 
  Re: f(char *p) { p=(char *)malloc(sizeof(6)); strcpy(p,"HELLO"); } main() { char *p="BYE"; f(p) printf("%s",p); } what is the output?
Answer
# 2
SOORY FOR POSTIN THE WRONG ANSWER THE ANSER WUD BE BYE COZ 
THE *P DIES IN THE FUNCTION ITSELF AS WE ARE NOT RETURNING 
THE STRING BACK IN THE MAIN PROGRAM
 
Is This Answer Correct ?    1 Yes 1 No
Deepa
 
 
 
  Re: f(char *p) { p=(char *)malloc(sizeof(6)); strcpy(p,"HELLO"); } main() { char *p="BYE"; f(p) printf("%s",p); } what is the output?
Answer
# 3
the output wll be hello , since the argument is overwritten 
with new memory in the function.

so in main, when it comes to printf,  p points to the 
allocatd memory, which contains hello
 
Is This Answer Correct ?    0 Yes 1 No
Anu
 
  Re: f(char *p) { p=(char *)malloc(sizeof(6)); strcpy(p,"HELLO"); } main() { char *p="BYE"; f(p) printf("%s",p); } what is the output?
Answer
# 4
The out put is "BYE".
Because the pointer p dies when function exit with out
return,in main pointer p points to only "BYE",so prinf
prints which p points in main.
 
Is This Answer Correct ?    0 Yes 0 No
Vijay
 
  Re: f(char *p) { p=(char *)malloc(sizeof(6)); strcpy(p,"HELLO"); } main() { char *p="BYE"; f(p) printf("%s",p); } what is the output?
Answer
# 5
it prints BYE on screen!!!
 
Is This Answer Correct ?    2 Yes 0 No
Prasad
 
  Re: f(char *p) { p=(char *)malloc(sizeof(6)); strcpy(p,"HELLO"); } main() { char *p="BYE"; f(p) printf("%s",p); } what is the output?
Answer
# 6
The output would be "HELLO"..

though we are not returning the string, we are making 
direct changes at the memory location..

so "bye" will be overwritten with "HELLO"


because we are using pointers, the dying pointer scenario 
is not applicabe here..

Its a pointer, not a variable..


This function will work similar to -> swapping two numbers 
using pointers..
juss check that prog if you fnd somewhere.. :-)
you will get the logic... :-)


Cheers...


--By the way a gud ques.. :-)
 
Is This Answer Correct ?    0 Yes 2 No
Shruti
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
Write a program to generate prime factors of a given integer?  3
Which of these statements are false w.r.t File Functions? i)fputs() ii)fdopen() iii)fgetpos() iv)ferror() A)ii B)i,ii C)iii D)iv Accenture5
What are the phases in s/w developed life cycle? wat is the diff b/w stack & queue...where do we use stack  5
write a program to generate 1st n fibonacci prime number  1
how to exchnage bits in a byte b7<-->b0 b6<-->b1 b5<-->b2 b4<-->b3 please mail me the code if any one know to rajeshmb4u@gmail.com Honeywell3
what is mallloc()?how it works? Excel3
void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result for all case TCS7
Who is invented by c? Infosys14
what are the general concepts of c and c++  1
#define min((a),(b)) ((a)<(b))?(a):(b) main() { int i=0,a[20],*ptr; ptr=a; while(min(ptr++,&a[9])<&a[8]) i=i+1; printf("i=%d\n",i);}  3
how to impliment 2 or more stacks in a single dimensional array ? iFlex1
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
what does " calloc" do? Cadence6
how to estimate the disk access time? e.g. the time between read one byte and another byte in the disk. Google3
Implement a function that returns the 5th element from the end in a singly linked list of integers in one pass. Microsoft6
How the processor registers can be used in C ? HP4
Which of the following about automatic variables within a function is correct ? a.its type must be declared before using the variable b.they are local c.they are not initialised to zero d.they are global. TCS3
Concat two string with most overlapped substring has to remove  "abcd"+ "cdef" = "abcdef  5
Program to find the absolute value of given integer using Conditional Operators N-Tech2
a=0; while(a<5) printf("%d\n",a++); how many times does the loop occurs? a.infinite b.5 c.4 d.6 TCS5
 
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