How to print the array?

What you are doing is printing the value in the array at spot [3][3], which is invalid for a 3by3 array, you need to loop over all the spots and print them. This will print it in the following format if you want more exact formatting you’ll have to change how the printf is formatted.

warning: assignment makes integer from pointer without a cast

When you write the statement the compiler sees the constant string “abcdefghijklmnop” like an array. Imagine you had written the following code instead: Now, it’s a bit clearer what is going on. The left-hand side, *src, refers to a char (since src is of type pointer-to-char) whereas the right-hand side, otherstring, refers to a pointer. This isn’t strictly forbidden because you may want … Read more

What is the difference between char s[] and char *s?

The difference here is that will place “Hello world” in the read-only parts of the memory, and making s a pointer to that makes any writing operation on this memory illegal. While doing: puts the literal string in read-only memory and copies the string to newly allocated memory on the stack. Thus making legal.

C pointers and arrays: [Warning] assignment makes pointer from integer without a cast

In this case a[4] is the 5th integer in the array a, ap is a pointer to integer, so you are assigning an integer to a pointer and that’s the warning.So ap now holds 45 and when you try to de-reference it (by doing *ap) you are trying to access a memory at address 45, which is an invalid address, so your program crashes. You should do ap … Read more

How do I use valgrind to find memory leaks?

Try this: valgrind –leak-check=full -v ./your_program As long as valgrind is installed it will go through your program and tell you what’s wrong. It can give you pointers and approximate places where your leaks may be found. If you’re segfault’ing, try running it through gdb.