Single characters can be replaced in a string. Given the following declarations, several things are possible.

 

char str[25] = "cot";

char ch = 'u';

char D[25] = "pat";

 

  • Replacing a single character using a char variable:
  • D[1] = ch;

This would result in D containing "put".

  • Replacing a single character using a char literal:
  • D[1] = 'e';

This would result in D containing "pet".

  • Replacing a single character using a single character from a string

variable:

  • D[1] = str[1];

This would result in D containing "pot".

 



Dinesh ThakurDinesh Thakur is a Columinist and designer with strong passion and founder of Computer Notes. if you have any ideas or any request please get @me on
linkedin FaceBook Twitter Google Plus