Main(){ char *a = "Hello "; char *b = "World";clrscr(); printf("%s", strcat(a,b));}

A) HelloWorld
B) Hello World
C) Hello
D) None of the above

Showing Answers 1 - 17 of 17 Answers

Amit

  • Dec 16th, 2005
 

it may print HelloWorld but concat using strcat(a,b) is not safe becoz it is not known waht is written in memory beyond "hello" and we are trying to attach "world" beyond "hello" so it may lose some important data .

  Was this answer useful?  Yes

maheboob

  • Dec 17th, 2005
 

the answer is HelloWorld. it's a normal 2 use 2 strcat opertaor. as one of the member said it's safe 2 use this operator. i totally unagree with him/her. coz v don't have 2 bother wat is written beyond Hello

  Was this answer useful?  Yes

Amit

  • Dec 29th, 2005
 

no..we have to be careful while using strcatfirst reserve sufficient space in memory against which we want to concat the stringFor examplesafe ischar a[20]="Hello";char *b="world";now we have allocated 20 bytes for a so now if we do strcat(a,b),it is totally safe using strcat.In large program we develop prog, keeping in our mind ..how to use memory and how to save memory and obviously without allocating may overwrite some important data so may lose some important information.

Varma

  • Jan 10th, 2006
 

Sorry its not "HelloWorld".... out put is "Hello World"...since there is a space after Hello in string "a"

  Was this answer useful?  Yes

Prateek

  • Jun 20th, 2006
 

When you say

char *a = "Hello ";

This piece of code goes into code section not data section. Code section can not be modified. Any operation to modify a will fail.

strcat(a,b) modifies a pointer. So the program will give an exception.

  Was this answer useful?  Yes

abhimanipal

  • Jul 22nd, 2009
 

It will give a sementation fault
The pointer a is allocated just sufficient space to accomodate "Hello". When we add beyond that it will give a seg fault

  Was this answer useful?  Yes

I think segmentation fault error is dependent on the operating system you are using.

I think if you run the code in Windows it will not give any error while when you run the same code in UNIX you will gate segmentation fault.

  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