So what does “return 0” actually mean?

Is it like php, where it returns its argument as the value of the function call? Is it just good practise? Yes, PHP and many other languages borrowed the return keyword from ‘C’. And in all the languages, the return keyword has the same function – to return from the function. Anything that follows return keyword is the value that is … Read more

Categories C Tags

What are .a and .so files?

Archive libraries (.a) are statically linked i.e when you compile your program with -c option in gcc. So, if there’s any change in library, you need to compile and build your code again. The advantage of .so (shared object) over .a library is that they are linked during the runtime i.e. after creation of your … Read more

What is EOF in the C programming language?

On Linux systems and OS X, the character to input to cause an EOF is Ctrl–D. For Windows, it’s Ctrl–Z. Depending on the operating system, this character will only work if it’s the first character on a line, i.e. the first character after an Enter. Since console input is often line-oriented, the system may also not recognize the … Read more

Strings and character with printf

If you try this: Output is: So ‘name’ is actually a pointer to the array of characters in memory. If you try reading the first four bytes at 0xbff5391b, you will see ‘s’, ‘i’, ‘v’ and ‘a’ To print a character you need to pass the value of the character to printf. The value can … Read more

segmentation fault : 11

This declaration: would occupy 8 * 1000 * 1000000 bytes on a typical x86 system. This is about 7.45 GB. Chances are your system is running out of memory when trying to execute your code, which results in a segmentation fault.

What causes the Broken Pipe Error?

It can take time for the network close to be observed – the total time is nominally about 2 minutes (yes, minutes!) after a close before the packets destined for the port are all assumed to be dead. The error condition is detected at some point. With a small write, you are inside the MTU … Read more

How do function pointers in C work?

Function pointers in C Let’s start with a basic function which we will be pointing to: First thing, let’s define a pointer to a function which receives 2 ints and returns an int: Now we can safely point to our function: Now that we have a pointer to the function, let’s use it: Passing the … Read more