Honey Well Written Test -  C Questions

I did not attempted the C paper but still I just had a look on C and java paper.  in C most of the question were programs and their out was  asked in LINUX environment.

1)
      int main()
      {
      char *a= "Novell";
      char  *b;
      b=malloc(10*sizeof(char));
      memset(b,0,10);
      while(*b++=*a++);
      printf("%s",b);
      return 0;
      }
2) int main()
     {
     printf("Hello");
     fork();
     printf("World");
     }

  
Showing Answers 1 - 2 of 2 Answers

1. output is Novell

2. output is Hello World World

because after 1st printf fork is executed .This creates the child process so child will execute 2nd printf & oncemore  by parent process.Hence world is printed twice.

  Was this answer useful?  Yes

ramubeedhimane

  • Jun 4th, 2006
 

for 2nd question,

o/p - helloworldhelloworld. ( this is the case on linux)

because, execution of  first printf statment stores in buffer. 

fork , forks helloworld. thats why, its print 2 times helloworld.

In case if u placed "\n" line buffer in first printf .

like : printf("hello\n"); directly prints on standard buffer.

thats the reson it only forks the second printf.

o/p - hello

  world world 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions