L
L
lightalex2018-12-19 21:52:53
C++ / C#
lightalex, 2018-12-19 21:52:53

How to convert char array to int c++?

Hello, friends!
There is a code that converts int to char:

unsigned char a[4];
int b = 124551;

*((int *) a) = b;

Tell me, is it possible to convert a char array to int by the same principle?
Or is the only way out - element-by-element enumeration of the array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2018-12-19
@lightalex

unsigned char a[4] = {'1', '2', '3', '4'};
int b = *(int*)a;

Only type conversions in C++ need to be done with plus casts, not in the C style.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question