The C Programming Language

Author: Brian W. Kernighan, Dennis M. Ritchie
All Stack Overflow 79
This Year Hacker News 2
This Month Reddit 7


by Bizkitgto   2017-12-06

I'd start with Harvard's CS50 on edx, it's the best course you'll find anywhere bar none. The instructor, Dave Malan is world class. The first half of the CS50 lectures are on C and on youtube. There's also r/cs50.

Also, the Richard Buckland lectures are all up in youtube as well, really good intro to C programming. People love this guy!

Here is the Aalto C Programming MOOC based on K&R.

If you want to learn C - you should read K&R 's The C Programming Language (the bible for C) at some point.

Stackoverflow is your friend where you can ask any question you have or bounce ideas off of others.

Learn Java OOP (here is an excellent course): MOOC

Free Code Camp for web design

Build your own operating system: NAND2TETRIS

Cave of Programming : All kinds of programming

Open Source Society University: This is a solid path for those of you who want to complete a Computer Science course on your own time, for free, with courses from the best universities in the World.

r/arduino for some embedded programming fun!

.....and of course for anything under the sun: &

For BSD:

For Linux:

For x86 assembly language: [How far down the rabbit hole do you want to go?]

Edit: I thought Scott Young's MIT Challenge. He completed the MIT Computer Science program in under 12 months using nothing but online resources.

by csp256   2017-12-06

Good news is you have previous experience and C is a very simple language.

Learn C The Hard Way has some weird shit in it (wtf does "make is your Python now" even supposed to mean?) but it is largely good and do tend to recommend it despite the warts.

Really though, why not go straight to the source?

Just make sure you master pointers. It is really useful to understand what memory is on a physical or near physical level to understand pointers. It is one of those concepts that makes instant sense if you come from a hardware point of view, but can trip up newbies with a software point of view.

by F14D   2017-12-06

K&R's C Book is also very good.

by anonymous   2017-11-13
@97amarnathk It was in pre-standard and in first standard of C language - C89 (adopted in 1989 as you could surmise). It was removed in all consecutive C standards. I read it in the famous C book from K&R:
by jasonlhy   2017-10-23
C is a very "strict" language. It do the right thing only if you write the right code. It has many undefined behaviors. One of the undefined behaviors I found when I studied the compiler course. The purposed grammar from allows this kind of structure, there can be statements after the switch but before the case labels. gcc also accepts this, but those statements will not be executed. Note: code modified from

#include "stdio.h"

int main () {

   /* local variable definition */
   char grade = 'B';
   int a = 1;

   switch(grade) {
      printf("great!\n" );
      a = a + 1;
      case 'A' :
         printf("Excellent!\n" );
      case 'B' :
      case 'C' :
         printf("Well done\n" );
         printf("a: %d\n", a);
      case 'D' :
         printf("You passed\n" );
      case 'F' :
         printf("Better try again\n" );
      default :
         printf("Invalid grade\n" );
   printf("Your grade is  %c\n", grade );
   return 0;
by anonymous   2017-09-05
@Beeran: As Bathsheba already said: [The C Programming Language by the developers of C: K&R](
by AviewAnew   2017-08-20

Reference Style - All Levels



Above Intermediate

Uncategorized Additional C Programming Books

by anonymous   2017-08-20

As per this SO answer from user Vijay Mathew:

Section 6.6 of The C Programming Language presents a simple dictionary (hashtable) data structure. I don't think a useful dictionary implementation could get any simpler than this. For your convenience, I reproduce the code here.

struct nlist { /* table entry: */
    struct nlist *next; /* next entry in chain */
    char *name; /* defined name */
    char *defn; /* replacement text */

#define HASHSIZE 101
static struct nlist *hashtab[HASHSIZE]; /* pointer table */

/* hash: form hash value for string s */
unsigned hash(char *s)
    unsigned hashval;
    for (hashval = 0; *s != ’\0’; s++)
      hashval = *s + 31 * hashval;
    return hashval % HASHSIZE;

/* lookup: look for s in hashtab */
struct nlist *lookup(char *s)
    struct nlist *np;
    for (np = hashtab[hash(s)]; np != NULL; np = np->next)
        if (strcmp(s, np->name) == 0)
          return np; /* found */
    return NULL; /* not found */

char *strdup(char *);
/* install: put (name, defn) in hashtab */
struct nlist *install(char *name, char *defn)
    struct nlist *np;
    unsigned hashval;
    if ((np = lookup(name)) == NULL) { /* not found */
        np = (struct nlist *) malloc(sizeof(*np));
        if (np == NULL || (np->name = strdup(name)) == NULL)
          return NULL;
        hashval = hash(name);
        np->next = hashtab[hashval];
        hashtab[hashval] = np;
    } else /* already there */
        free((void *) np->defn); /*free previous defn */
    if ((np->defn = strdup(defn)) == NULL)
       return NULL;
    return np;

char *strdup(char *s) /* make a duplicate of s */
    char *p;
    p = (char *) malloc(strlen(s)+1); /* +1 for ’\0’ */
    if (p != NULL)
       strcpy(p, s);
    return p;

Note that if the hashes of two strings collide, it may lead to an O(n) lookup time. You can reduce the likely hood of collisions by increasing the value of HASHSIZE. For a complete discussion of the data structure, please consult the book.

by anonymous   2017-08-20

The conflicting function getline() is a GNU/POSIX extension.

K&R state that they address specifically ANSI C in their book (c.f.), which does not provide this function.

The authors present the complete guide to ANSI standard C language programming.

In order set gcc into "K&R compatibility mode" you can specify the ANSI or ISO modes for compilation. These are intended to disable extensions, e.g., the function getline(). This could eventually eliminate the need to edit other examples provided by K&R as well.

For example, the following compile just fine:

$ gcc test.c -ansi
$ gcc test.c -std=c89

(Except that they complain about the implicit default return type of main() with -Wall.)

Apparantly on some systems, these modes may not work as presented here (apparantly some version(s) of Mac OS fail to correctly disable all extensions). I tested this successfully on my machine:

$ gcc --version
gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
by anonymous   2017-08-20

Code should be well formatted e.g code inside curly braces ({ }) should be indented properly (this makes it easier to read your code).

#include <stdio.h>

int main(int argc, char *argv[])

Variables should be descriptive (helpful if other people are reading over your code).

    int largest = 0;
    int num1 = 0, num2 = 0, num3 = 0;

The newline character ('\n) isn't necessary, unless you want scanf to take the newline character as part of your input.

    printf("Enter the first number : ");
    scanf("%d", &num1);

    printf("Enter the second number : ");
    scanf("%d", &num2);

    printf("Enter the third number : ");
    scanf("%d", &num3);

This is a much cleaner and simpler check to see which is the largest number. (taken from Rishav Choudhuri's code above)

    if (num1 > num2 && num1 > num3)
        largest = num1;
    else if (num2 > num1 && num2 > num3)
        largest = num2;
        largest = num3;

    printf("The largest number is : %d", largest);

    return 0;

I also recommend reading this book The C Programming Language 2nd Edition and reading some tutorials online

also be sure to write lots of code as well :D