Ad

XOR Operation Of 0 With String "hello World" In C

- 1 answer

This code gives Segmentation Error can someone help. I've to XOR string "HelloWorld" with 0.

#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>

int main()
{
    char str[] = "Hello World";
    int n = strlen(str);
    char y[n];
    
    for (int p=0;p<n;p++) {
      y[p]=str[p]^0;
      printf("%c",y[p]);
    }
    return 0;
}
Ad

Answer

Shouldn’t the char array be n + 1 size to store null character? At least that should be the issue on C, but I think it should be similar on c++

Ad
source: stackoverflow.com
Ad