How to concatenate two strings using pointers in C

1 Answer

0 votes
#include <stdio.h>
 
#define SIZE 64
 
int main() {
  
    char str1[SIZE] = "c", str2[] = " programming";
    char *ps1 = str1;
    char *ps2 = str2;
  
    while(*(++ps1));
  
    while(*(ps1++) = *(ps2++));
  
    puts(str1);
    puts(str2);
  
    return 0;
}
 
 
 
/*
run:
 
c programming
 programming
  
*/

 



answered Aug 5, 2021 by avibootz
edited Aug 5, 2021 by avibootz

Related questions

1 answer 148 views
3 answers 230 views
230 views asked Jun 13, 2017 by avibootz
1 answer 160 views
...