Thursday 5 September 2013

Hello World!

The code is as so:



The code appears to be simple. And yes, it is simple.

"Just try to feel the C Compiler."

Now, I am gonna explain the code, line-by-line:

Line 1: We include the file "stdio.h" in the program. This effectively means that, there is some code inside this file, "stdio.h" and we want to use it. So we simply import the file, meaning that we kinda copy all the code in that file and paste it at the first line of this file.

Line 3: The main function is where the story begins. It is where the execution starts. And the program execution ends with the end of the main() function.

Note: I know, you must be thinking, "Dude, what the hell is a function? And why the hell is the simple word "main" followed by two parentheses? Well these doubts will be cleared soon. For now just think of the following four lines as lines that must be there in every C program that you write:

Just write all your code within the "curly" braces(some people prefer to call it "flower brackets", I don't!)

Line 6: printf. This is the thing that is gonna save you for the whole of your life. Trust me when I tell you that any useful program will not be correctly written the first time. You will make a ton of mistakes and then you will use the printf statements to find out what was the mistake in your code.

printf has a separate story of itself. And this story will be narrated soon in another blog post.

Line 8: Another syntactical pitfall. Just take it from me. Your code must be there in the structure as shown below:



So, that's what it is! Now you know how to make the computer print "Hello, World!". Great! Now there are two group of people among the ones reading this:

1. What the hell is this guy doing? C is too much. I am just gonna quit.

2. This is so cool! Can I do more of this? And can I do more complicated things too? Can I this.. Can I that... Et al..

And the answers to the two kinds of people:

1. Dude(or Gal), knowledge of C is required for a person to be considered as Literate! (its not that bad.. But trsut me, Just get through these few blogs and once you get what I am doing.. You will just love programming in C)

2. I have nothing to say. You can do anything. yes. Anything. And if you are having a scale imaging the scale of anything:

You can create:
  • Hello World program
  • Sort an array
  • take the user's name and print it back
  • play tic-tac-toe with the user
  • play hangman with the user
  • make an operating system(MAC OS X is written in C!)
So the opportunities are endless, You just need to have a kickass idea!

No comments:

Post a Comment