Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Dissecting 'Hello World' in C

Analyzes the C code for a simple 'Hello World' application to give you some familiarity with the language and the way it works.

On Saturday, April 23rd 2005 at 09:08 AM
By Andrew Pociu (View Profile)
***--   (Rated 2.7 with 7 votes)
Contextual Ads
More C Resources
Advertisement
C is not such a current language anymore, it was replaced by C++ long ago and recently C++ is being replaced by the .NET Framework. If I would stop the paragraph right here this tutorials is sure to get some hate comments, because there's something wrong about the first sentence, and I don't mean to misinform you: C is not fully replaced by C++, the same as C++ is not fully replaced by .NET. This means that for certain projects, C++ is far more appropriate than C# or VB.NET, and sometimes even C is more appropriate than C++. Most game developers - for example - use both C and C++ code in their applications.



So if you are not planning to work on projects that require close access to the computer's hardware (such as graphic cards) you will probably never need to code something in C. However it's important to know at least the very basics of the C language, because this gets you closer to understanding how programming works. C, being a low level language, most of the time requires more lines of code (and therefore time) to accomplish something that you could do in C# with only a few lines. On the other hand, C offers you more control over the computer.



How does the code of a C Hello World application look like?






#include


void main(void)

{

   printf("Hello World");

}




On the first line a header file is included: stdio.h. This file contains code that you will need in most of your C applications, this means that in almost any file you will see the #include line. In our case, we need this header file because we use the printf() function which is declared there.

stdio.h, even though its extension is not c, it's a C file also - it contains C code. Including this file in your code is just like pasting the contents of that file into your code.



Moving on, we have a function named main(). Before its name, we can see a return type void. It's important to remember that functions can return values of different types (strings, numbers, etc.). You need to define the type the function returns, before its name. Here the the type is void, which is actually not a type, it rather specifies that the function has no return type whatsoever, meaning it doesn't return any value.

In the parenthesis the arguments are declared. Arguments are values that the function can take inside it (again, same values that can also be returned: strings, numbers, etc.). Having void instead of an argument means we want the function to take no arguments.

A C file can contain multiple functions, but the compiler wouldn't know with which one to start. That's why there is a need for a function name main. main is always the starting point for the application.

The { and } braces define the start and the end of the function. What's inside them belongs to the function.

And inside them we have a line that calls the printf() function. The printf() function is probably the most popular function among C learners. This function outputs the argument it takes to the console. In our case the argument is the string "Hello World".



What is the result of running this compiled code?




Hello World
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by manish on Tuesday, December 22nd 2009 at 11:49 AM

plz..in this tutorial........some modification is necessary.....because this is not the actual answer.....


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs C Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Sponsors
Discover Geekpedia

Other Resources