0
Why is 'r' and "r" different in C? Thank you already🤗
23 ответов
+ 3
The difference between 'r' and "r" is that the 'r' is especially quoted in a single quote which shows it is a character type data which is char.
Like
//Character Datatype
char a = 'r';
putchar(a);
//Character Array Datatype
char *a = "r";
printf(a);
the "r" is especially quoted in a double quote which shows it is a character Array data type that is string as we know that string is the Array of characters with null character.
+ 9
First is a char and the second is a string
+ 3
You can check this lesson:
https://www.sololearn.com/learning/2912/
+ 3
JESUS EDUARDO CANUL KOYOC I'm unable to access the link. If I agree through sololearn application, it never opens. If I do with browser, it asks me which language I wanna learn. Please share some other way to access that lesson
+ 3
'r' is a single character which is written in single quotes. It can be declared as:
char rchar = 'r';
Whereas "r" is a string,
And it can be declared as:
string rstring = "r";
Thank you...
+ 2
Why does "r" and 'r' work differently in fopen() function in C? In fact 'r' doesn't even work
+ 2
Bot
I think you misunderstood him.
He said that "r" is for character array with AT LEAST 1 character (that's null character).
When he said that the minimum memory demand is at least 2 bytes he's referring to this example: "r".
+ 2
Bot
"So" - that way he concludes that the minimum memory demand is at least 2 bytes in this example.
First he gave general information and then he referred to that particular example "r".
It is minimum, size of char is minimum 1 byte but it could be bigger.
https://en.m.wikipedia.org/wiki/C_data_types
+ 2
Dear Rishi,
According to the rules of C programming language, there are string constant which is written in the double quotes and they are the sequence of characters which ends or terminate with the null character.
char a[5] = {'A', 'm', 'a', 'n', '\0'};
char a[5] = "Aman";
Here, the null character is automatically added at the end.
So, the rule of string constant says that always use double quotes in string.
Now, discuss on the character constant. Character is a single value enclosed in 'and having respected ASCII (American standard code for information interchange) code.
In character constant, we use single quote. Because it holds only one character.
Therefore, 'r' is the character whereas "r" is the string. This is the distinguish between 'r' and "r".
Thanks for Asking Question
Have a nice day 🎉.
CMDian
+ 1
Rishi same here, I can't access external links, simply doesn't work. Haven't try on pc
+ 1
Rishi Any single character in C enclosed with single quotes is of type <char> while anything enclosed in double quotes is of type <char_arr>. C doesn't have a string data-type. Whenever you use double quotes, a char array is created internally in the programming language. The <char> type can also be considered as a short-short-int type.
+ 1
Jan Markus sorry sir but a string can be of length 0, so the minimum memory demand is at p
least 1 character (the null byte) :
https://code.sololearn.com/cqw9CaBdDI0y/?ref=app
+ 1
Rishi that's because fopen expects an array of chars(or string), not a char
+ 1
Quanti sorry but he said "so" which means that he is referring to strings in general. and also if he was referring to "r" then he would not say "minimum" caz its size is exactly 2, it doesnt vary
+ 1
Quanti oh sorry...nvm i take my words back🤖
+ 1
Ex
Char x= 'r' ;
+ 1
In the given code, 'r' is a character constant whereas "r" is a string constant.
+ 1
They are different because of the ' and "
I don't know about c but I know that cpp and c are kind of the same
' is for char ,which is character
" is for string , which you need #include <string.h> or <ioatream>
in this case , use 'r' because it is char and it takes only 1 cell in storage , unlike string which takes 4
0
Thank you all 🤗
0
Ayaz Ben no