No.4ベストアンサー
- 回答日時:
> I didn't even know this at all~. Is there any specific reason for this? I mean I don't get the point of avoiding to just put the string type in there and let things go easier.
I think you have got the point.
If there were easier way of writing, why don't you use that?
I mean, there is a theory behind it, but a language should give you a sort of "shortcut".
Now you understand, in theory, there is no such string type in C. There is only arrays filled with binaries.
However, even though it were correct, you would be messed up if C forced you to write a message every time like this:
char str[] = {'T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'v', 'e', 'r', 'y', ' ', 'b', 'u', 'l', 'l', 's', 'h', 'i', 't', '!', '\0'};
The theory requires this. Do you want to write like this every time? The answer would be "No kidding!".
Thus, almost all languages provide some "shortcuts" of writing, in order to let you avoid pain in the ass. Those kinds of short cuts are called "Syntax Sugar", which implies sugar makes some very bitter syntax juice barely drinkable.
As a result, the syntax sugar of array with characters in C could be written as:
char str[] = "This is a piece of cake!"
This relatively gives you no headache, related to "right meaning" and its syntax.
> Maybe I should have known this and again, I know this is partly my fault of not attending those classes but like for what reason? I've had multiple lectures on algorithms and computation in C and yet didn't know this...
I am sorry to hear that, but, to be honestly, C is not a suitable language for new comers into the world of programming. The school, or you had better start with much easier language, like Python or Ruby, popular one now a day.
C really sucks. C is pain in the ass. C is a tablet of anti-aspirin.
At least, your responsibility about this is less than 50%. The remainder is C itself.
ありがとうございます。
I came to see that maybe C language is not that sophisticated or almost perfect as I thought. People around me say things like C is the most powerful language and there is almost nothing you can't do with it and I was like okay, then I hafta learn this but no~ it was not that easy and simple... You are saying the language itself is not really well-built, ryt? Ofc not like the structure is cracked or something but at least I think it's not for someone who just started coding like me (some ppl around me have been coding as a hobby for years) and I don't like how professors are like "you know this stuff, ryt? and this one too, so you must be able to do this matrix analysis and that's why it's due tomorrow".
Since I can't see the intention of those great brains that made these things from nothing yet, it feels like maybe I should just accept how it is and not really care about the whys when confronting with the complexity of programming languages.
Thank you as always~ (。◕‿‿◕。)
No.1
- 回答日時:
You may misunderstand.
In C, "Hello" is not a string. It is definitely an array.
Frankly speaking, C does not have any "string" type, which the other ordinary programming languages have.
What C only has is an array filled with a bunch of binaries, and sometimes, those binaries are recognized as "Characters", or char.
Therefore,
char str[] = "Hello";
is something like an alternative way of writing, and literally, it directly means
char str[] = {'H', 'e', 'l', 'l', 'o' ,'\0'};
.
That is all.
ありがとうございます。I didn't even know this at all~. Is there any specific reason for this? I mean I don't get the point of avoiding to just put the string type in there and let things go easier. Maybe I should have known this and again, I know this is partly my fault of not attending those classes but like for what reason? I've had multiple lectures on algorithms and computation in C and yet didn't know this...
どうして?と思う。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
似たような質問が見つかりました
- C言語・C++・C# c言語配列の結合についてです。 なぜうまくいかないのでしょうか。 #include <stdio.h 4 2022/05/30 22:42
- C言語・C++・C# c言語 プログラムのエラー 1 2023/02/11 20:31
- C言語・C++・C# C言語初心者 構造体 課題について 2 2023/03/10 19:48
- C言語・C++・C# 宣言する関数の形が決まっている状態で、 str1とstr2の文字列をこの順に引っ付けてstrに保存し 2 2022/05/30 18:21
- C言語・C++・C# C#テキストボックスの文字を配列にいれてその後表示する 4 2022/07/17 04:47
- C言語・C++・C# str[j++]の意味 2 2022/08/30 16:20
- C言語・C++・C# 【C言語】全角文字の配列を、全角のまま1文字ずつ出力する方法 4 2023/05/09 15:08
- SQL Server [SQLServer] テーブル名からカラム名を取得する 1 2022/08/23 21:20
- C言語・C++・C# C言語について質問です。 以下のような結果を出すためにはどのようなコードが良いですか?サンプルコード 3 2022/11/01 16:19
- その他(プログラミング・Web制作) PythonでLoopを使って配列内の文字列を結合する。そして [] を削除する 1 2022/03/31 23:28
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
C言語 配列の長さの上限
-
配列を使わずに、変数名を動的...
-
配列を含む構造体の初期値について
-
C# Listを使わずに2次元配列の...
-
パイソンの
-
配列で格納したものをmsgboxで...
-
擬似コード 長さがmの配列でな...
-
ExcelVBAで質問です。離れた二...
-
複数の選択範囲の行番号を個別...
-
C言語で特定列だけを抽出して配...
-
【速いブラインドタッチ】手を...
-
C言語 配列の再初期化
-
ファイルの読み込みとメモリ確...
-
C言語でcharの足し算
-
char型の二次元配列の意味が分...
-
COBOLのINITIALIZEにあたるもの
-
VB.NET 構造体の配列の検索機能...
-
C# 配列の変数宣言について。
-
配列の参照渡しで型が一致しま...
-
メモリの初期値
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
C言語 配列の長さの上限
-
配列の参照渡しで型が一致しま...
-
配列を使わずに、変数名を動的...
-
VBで構造体の配列を関数に渡す...
-
配列で格納したものをmsgboxで...
-
unsigned char配列への入力の仕方
-
C# Listを使わずに2次元配列の...
-
C# 配列の変数宣言について。
-
擬似コード 長さがmの配列でな...
-
【速いブラインドタッチ】手を...
-
パイソンの
-
C言語初心者 ポインタについて...
-
ExcelVBAで質問です。離れた二...
-
配列を含む構造体の初期値について
-
複数の選択範囲の行番号を個別...
-
Functionの戻り値を2次元配列...
-
C++ vectorに配列をプッシュしたい
-
先頭アドレスとは何ですか?
-
テキストファイルから文字列を...
-
Redimした動的配列はEraseする...
おすすめ情報