#include <iostream>
#include <cstring>
using namespace std;

int main(int argc, char* argv[])
{
	 const char* p = "1111";
	 int len = strlen(p) - 1;
	 int a[len];
	 for(int i = 0; i <= len; i++)
	 {
		 a[i] = ~(p[i]- '0');
	 }
	 for(int i = 0; i <= len; i++)
	 {
		 cout << a[i];
	 }

}

Why do i get -2 -2 -2 -2 ? I`m not using ~ corect or ?

The question is...What were you expecting? Was it something like below

#include <iostream>
#include <cstring>
using namespace std;

int main(int argc, char* argv[])
{
	unsigned char p[] = {'1', '1', '1', '1'};

	unsigned char a[4];

	for(int i = 0; i < 4; i++)
	{
		 a[i] = ~(p[i] - '0');
	}
	for(int i = 0; i < 4; i++)
	{
		 cout << (unsigned int)a[i] << endl;
	}

}

Which produces

254
254
254
254

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.