Why we can't simply make a empty string in C?
▲ 0 r/AskProgramming+1 crossposts

Why we can't simply make a empty string in C?

I was trying to make a code in C when I thought I need to make an empty array.
I did initially as always like
string s ;
and done but it showed me a segmentation fault.

So I searched for answers when I got a Stack Overflow code:

char s[10] = {'\0'};

// Source - https://stackoverflow.com/a/4142796

I just want to know how this works and why normal initialization doesn't?

u/Infamous-Research805 — 7 days ago

Can anybody explain what is segmentation fault?

I was solving a pset when I stumble crossed a very strange thing in debug "Segmentation fault (core dumped) ".

The context is that in main function i was trying to strlen value of a string in a variable and it shows error.

Can anybody explain what it means?

reddit.com
u/Infamous-Research805 — 7 days ago
▲ 2 r/cs50

Can anybody explain what is segmentation fault?

I was solving a pset when I stumble crossed a very strange thing in debug "Segmentation fault (core dumped) ".

The context is that in main function i was trying to strlen value of a string in a variable and it shows error.

Can anybody explain what it means?

reddit.com
u/Infamous-Research805 — 8 days ago
▲ 4 r/cs50

Should I actually submit my problem set solutions ?

Lately, I have started to attend cs50x lectures of 2026 using edx since I didn't have anything to do during my summer vacations. I am also doing problem sets after completing the lecture.

I am currently on week 3, so should I actually submit my projects or not? (I was doing it for fun, but I am actively working too ...need opinions)

reddit.com
u/Infamous-Research805 — 9 days ago
▲ 5 r/cs50

View on strings not being an actual data type

What are your views on strings being used to widely, yet it is not a data type in C? (I think its non-primitive for most programming languages)

reddit.com
u/Infamous-Research805 — 12 days ago
▲ 3 r/cs50

Pset 1 of CS50x

Does anybody know if it is possible to initialize and assign values to the variables in C using loops?

Edit: For example, if I want to use 5 variables (assume x1 to x5) so is there any way I can use for loop to use the value of i = 1 . Hence , it just initializes x1 to x5 later receives the values but without an array.

reddit.com
u/Infamous-Research805 — 13 days ago