Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need some help with C programming [closed]

Tags:

c

I am new to C programming and I am having problems understanding common pitfalls and common usages of different library functions in C programming. Can some one point me to a good resource where I can learn subtleties in C programming. Also can some one point me to a good resource learn debugging tools like gdb.

Also I want to know what is the difference between char *c="hello"; and char c[10]="hello" . Can some one tell me which one is recommended over the other in different situations.

Thanks & Regards,

Mousey.

like image 232
mousey Avatar asked May 10 '26 07:05

mousey


1 Answers

char *c = "hello";

That makes c a pointer and is pointing to memory that should not be modified (so you cannot modify the data). But since c is a pointer, you can change where it points to.

char c[10] = "hello";

That makes c an array and arranges to have the array initialized with the specified string. Since it's an array, you can modify the data (although make sure you don't overflow the buffer) but you cannot change where in memory c references.

like image 119
R Samuel Klatchko Avatar answered May 19 '26 12:05

R Samuel Klatchko