TuKeZ
TuKeZ

Reputation: 11

Is there a way to initialize arrays with mixed chars and "strings"

I would want to initialize char array during compilation time with least amount of manual work.

Is there a working shorthand format for this

char arr[5] = {0x4, 'a', 's', 'd' 'c'};

such as

char arr[5] = {0x4, "asdc"};

Upvotes: 0

Views: 101

Answers (2)

user2672107
user2672107

Reputation:

You could integrate the char int the string with escape sequences:

char arr[6] = { "\x04asdc"};

edit: corrected the wrog length of the array.

Upvotes: 1

Some programmer dude
Some programmer dude

Reputation: 409364

No that's not possible. But you could do

char arr[] = "\04asdc";

The problem with this is that is would not be exactly like the original array you show, since it would include the string terminator and therefore have six elements.

Upvotes: 1

Related Questions