frentzy

Pointer, string cu const char * referinta

Oct 26th, 2020 (edited)
938
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5. void exchange(const char*& p1, const char*& p2) {
  6.     p1 = p2;
  7. }
  8. void wow(const char*& p) {
  9.     char ceva[256] = "";
  10.     strcpy_s(ceva, "hahalero");
  11.     char* p2 = ( char*)malloc(sizeof( char) * 255);
  12.     int i = 0;
  13.     for (const char *p = ceva; *p != '\0'; ++p) {
  14.         *(p2 + i++) = *(p);
  15.     }
  16.     p2[i] = '\0';
  17.     exchange(p, p2);
  18.    
  19. }
  20.  
  21. void main() {
  22.     int x = 5;
  23.     const char* p;// = (const char*)malloc(sizeof(const char) * 255);
  24.     wow(p);
  25.     cout << p;
  26. }
  27.  
  28.  
RAW Paste Data