开发者

What is the variable type of syntax: 'somestring' in Objective-C?

开发者 https://www.devze.com 2023-03-29 09:49 出处:网络
I saw this in Apple\'s framework files enum { kAudioFormatLinearPCM= \'lpcm\', kAudioFormatAC3= \'ac-3\' }

I saw this in Apple's framework files

enum
{
    kAudioFormatLinearPCM               = 'lpcm',
    kAudioFormatAC3                     = 'ac-3'
}

What is the开发者_JAVA百科 type of 'lpcm'and 'ac-3'?

With a single character in the single quote like this 'a', I know it is a char; With double quotes like this "text", I know it is a string.

But this? This makes me confused.


Well first your in a type enum so it can only represent a int. I think apple using it to create unique vals for the enum but also wants it human readable.

For a much better explanation see: What is the type of an enum whose values appear to be strings?


Contrary to popular belief the type of 'c' in C is int, not char. When you do something like char c = 'c';, there will be an implicit conversion from int to char, same as if you had written char c = 99;.

So to answer your question: the type of 'abcd' is int, same as the type of 'c'.

0

精彩评论

暂无评论...
验证码 换一张
取 消