0

Diffrence of String between C, C++ and Java

What is the diffrence in String in C++ and Java and how to declare it. Is char[20] is String?? Help giys

7th Feb 2020, 6:50 PM
Zeeshan Anwer
2 ответов
+ 2
Declaration differences? C has no direct declaration of string. So must use a charecter array.. So string in c are sequence charecter terminated by \0. Ex: char a[50]="Solo learn"; In c++: string a="Solo learn"; In java: Sting s="Solo learn"; or String s=news String("Solo learn");
7th Feb 2020, 7:22 PM
Jayakrishna 🇮🇳
+ 1
You have to define what string you are talking about. There are the raw strings like you use them in C, which are basically just arrays of chars with a 0 ('\0') at the end. Functions like printf are designed in a way that they'll recognize this 0 as the end of the line. Then there are higher types of strings in the different languages that build a casing around the raw material and add certain behaviors and rules. In C++ that's the type 'string' which you have to include and which has all sorts of methods, like push_back, pop_back and such. While in C++ strings can be changed, strings in Java are 'immutable', which means that you have to create a whole new object when you want to change a letter or something. There's probably a lot more to say, but does this give you a bit of a feeling already?
7th Feb 2020, 7:26 PM
HonFu
HonFu - avatar