Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between 0x and '\x' in C++? [duplicate]

Tags:

c++

I know that hex-decimal number is usually prefixed with 0x in C/C++ language. For example, 0x5A means 90 in decimal. But I saw an example code using single-quoted character with '\x'.

BYTE outputBuffer[index++] = '\x5A'; // instead of 0x5A

Is the meaning of '\x5A' exactly the same as 0x5A?

If so, why is there alternative way of hex-decimal notation?

like image 475
yufit_in_Japan Avatar asked Feb 16 '14 05:02

yufit_in_Japan


People also ask

What is the difference between ++X and X++ in C++?

++x is a prefix operator in which the value will be incremented first and then used. X++ is a postfix operator in which the given value of x will be used and then the value will be incremented Here the value of b will be returned as 5 as in case of a postfix operator the value of x is used first than incremented

What is the difference between C++0x and C++11?

C++0x was the name for the standard before it was released / finalized. Once it was finalized (in the year 2011), we were able to name it properly. That is, C++11. Show activity on this post. Because the standard was planned to be released / approved in 200x, but actually was approved in 2011. Show activity on this post.

What is the difference between ++X and X++ in an image?

++X and X++ difference in an image. Both the prefix increment and the postfix increment add one to the value of a number. Their return value is the only distinction between the two. The former returns the value of x after first incrementing (++), so ++x. What Is the difference between ++ x and x ++ in Javascript?

What does 0x mean in hexadecimal numbers?

This adds the 0x prefix to the hexadecimal numbers when they are written in buf. The correct format is "0x%x" as ouah and Carl Norum said. Whatever gpbImageData [100] content (pointer or number), %x will print its value as a hexadecimal number. 0x is just a text. Maybe "gpbImageData" is an array of pointers. Not the answer you're looking for?


1 Answers

For a character, both are quite equal.

But only one can be mixed into a string with other normal characters. "ABC\x5A"

And only one can be used to initialize a large integral type: long long x = 0x1234567812345678LL;

like image 91
Ben Voigt Avatar answered Sep 21 '22 10:09

Ben Voigt