Top

Discussion

What is the output of this program?

#include 
#include  
int main()
{
  int i;
  char *ptr;
  char *fun();
  ptr = fun();
  printf(" %s", ptr);
  return 0;
}

char *fun()
{
  char disk[30];
  strcpy(disk, "letsfindcourse");
  printf("%s ",disk);
  return disk;
}

 

  • A.letsfindcourse
  • B.Compilation error
  • C.letsfindcourse letsfindcourse
  • D.garbage value

Answer: A

 

Here disk is an auto array, when array is used as return value, it will die when the control go back to main() function of a program. Thus memory in c alone prints.

No comment is present. Be the first to comment.
Loading…

Post your comment