char *ch = "abcde";
char c[4];
how to copy 'ch' to 'c'?

Answer Posted / parth ujenia

main()
{
char *ch="abcd";
char c[4];

for(int i=0;i<4;i++)
{
c[i]=*ch; //assign value to char c[i].
*ch++; //switch to next address of ch!
}

for(i=0; i<4 ;i++)
{
printf("%c - ",c[i]); //output will: a - b - c - d -
}

getch();

}

Is This Answer Correct ?    18 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is iostream in c++ used for?

549


Differentiate between an external iterator and an internal iterator? What is the advantage of an external iterator.

614


Write a program using display() function which takes two arguments.

609


Write a program which uses functions like strcmp(), strcpy()? etc

613


What is type of 'this' pointer? Explain when it is get created?

586






Is c++ a dying language?

583


What is the use of c++ programming language in real life?

562


What is java and c++?

658


What is the hardest coding language to learn?

598


Are there interfaces in c++?

556


When should I use unitbuf flag?

586


When the constructor of a base class calls a virtual function, why doesn't the override function of the derived class gets called?

566


When there is a global variable and local variable with the same name, how will you access the global variable?

616


Is c++ vector dynamic?

572


What is the use of data hiding?

593