What is C K&R Syntax?

Okay I just want to start out and say that this is outdated. The only reason why I am posting about this is because I find the history of technology very interesting and I want to share what I’ve read up on.

Alright so, if you’re a programmer you’re probably aware of multiple types of syntax. With Python we have:

def MyFunction:
    print("Hello World")

MyFunction()

In Java we have:

public static void main(String[] args)
{
    Chicken();
}

void Chicken()
{
    System.out.println("Hello World");
}

In standard C/C++ we have:

int main(void)
{
    printf("Hello World");
    return 0;
}

But in the old days we had something called K & R syntax in C. It looked like this:

int Chicken(a, b, c)
int a;
float b;
char c;
{
   return 0;
}

What’s interesting about this is that some modern compilers still support this syntax but will scream at you and tell you to not do it. However there’s some important things to note here. Look at the following code block.

int Chicken(a,b,c)
int a;
int b;
{

}

If you notice, I never declared the data type for c. By default, the compiler will use integer data types for anything that is undeclared. So the entire concept behind K & R syntax is that you define the function name, and it’s inputs. Then, you define the types of inputs afterwards. It’s very different from what I was taught in university. I just wanted to share this. Hopefully someone finds this interesting. 🙂

Leave a Reply

Your email address will not be published.