0

Why is 'r' and "r" different in C? Thank you alreadyš¤

10th Jun 2021, 6:14 AM
Rishi
23 Respostas
+ 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.
9th Jul 2022, 2:33 PM
AMRIT KUMAR
+ 9
First is a char and the second is a string
10th Jun 2021, 12:08 PM
Alex
+ 3
You can check this lesson: https://www.sololearn.com/learning/2912/
10th Jun 2021, 7:18 AM
Cmurio
+ 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
10th Jun 2021, 9:35 AM
Rishi
+ 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...
11th Jun 2021, 7:38 AM
Akshat Sharma
+ 2
Why does "r" and 'r' work differently in fopen() function in C? In fact 'r' doesn't even work
11th Jun 2021, 4:08 AM
Rishi
+ 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".
11th Jun 2021, 4:40 AM
Lofty
+ 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
11th Jun 2021, 4:53 AM
Lofty
+ 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
11th Jun 2021, 8:29 AM
AMRIT KUMAR
+ 1
Rishi same here, I can't access external links, simply doesn't work. Haven't try on pc
10th Jun 2021, 10:08 PM
Lofty
+ 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.
11th Jun 2021, 3:17 AM
Calvin Thomas
+ 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
11th Jun 2021, 4:24 AM
Bot
+ 1
Rishi that's because fopen expects an array of chars(or string), not a char
11th Jun 2021, 4:26 AM
Bot
+ 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
11th Jun 2021, 4:44 AM
Bot
+ 1
Quanti oh sorry...nvm i take my words backš¤
11th Jun 2021, 5:01 AM
Bot
+ 1
Ex Char x= 'r' ;
11th Jun 2021, 8:42 PM
mohamed alkasem
+ 1
In the given code, 'r' is a character constant whereas "r" is a string constant.
12th Jun 2021, 3:49 AM