Archive

Posts Tagged ‘Middle Level Language’

Programming Language C : Part 3

April 27, 2009 2 comments

Last day, I’d ended on the basic structure of the C Programming Language. Today, we shall start to do real programming. It is really fun.

Ok. Lets do a small program to print your name:

c1

This program will give you output like: c2

Now, we shall move to DATA Types.

As we know, there are many types of data in our real world. For example, the Integers, the Floating point numbers, Characters etc.

In case of C, there also exist all of them. In case, we want to use them, we need to “INITIALIZE” them to the Compiler. The method is like this:

c3Here we can see, “int a” declares an integer called ‘a’ without any value. But, “int b = 5” declares an integer called ‘b’ with a value 5 assigned in it. Similarly for floating point numbers, ‘float’ is used and for characters, “char” is used. All these ‘int’ or ‘float’ or ‘char’ are called “keywords” in C.

We shall look further more keywords in C:

c4

All these keywords have their own meanings and jobs to do. We shall look them further, while we will need them in future.

Now, there is a question. I know, I can use int as a keyword to mean the integers. But, how long that integer can be? Int x = 1234567891011121314151617…..??? There should be a limit of this.

char     => a single byte, capable of holding one character in the local character set

int        => an integer, typically reflecting the natural size of integers on the host machine

float     => single-precision floating point

double =>  double-precision floating point

In addition, there are a number of qualifiers that can be applied to these basic types. short

and long apply to integers:

short int sh;

long int counter;

The word int can be omitted in such declarations, and typically it is. The intent is that short and long should provide different lengths of integers where practical; int will normally be the natural size for a particular machine. short is often 16 bits long, and int either 16 or 32 bits. Each compiler is free to choose appropriate sizes for its own hardware, subject only to the the restriction that shorts and ints are at least 16 bits, longs are at least 32 bits, and short is no longer than int, which is no longer than long.  The qualifier signed or unsigned may be applied to char or any integer. unsigned numbers are always positive or zero, and obey the laws of arithmetic modulo 2n, where n is the number of bits in the type. So, for instance, if chars are 8 bits, unsigned char variables have values between 0 and 255, while  signed chars have values between -128 and 127 (in a two’s complement machine.) Whether plain  chars are signed or unsigned is machine-dependent, but printable characters are always positive.  The type long double specifies extended-precision floating point. As with integers, the sizes of floating-point objects are implementation-defined; float, double and long double could represent one, two or three distinct sizes.

The Programming Language – C


Hello and Welcome to all our readers.

This is Jayanta here. I will be posting topics / tutorials on ‘C’ programming Language.

Before everything, at first, I want to share a brief history of C with you.

This ‘C’ was written by Dennis Ritchie for the OS called “Unix“. While, he was developing Unix, he realized that, there should be a good programming language, so, he developed it.

The simple naming convention behind “C” is, prior to C, there was a language called “B”. B actually was the abbr. of ‘BCPL‘. So, as a casual naming convention, after B, it was named C !!

Before Starting C, I want to share some resources about C.

The software, where you want to write , edit ,run C programs (these softwares are generally called IDE – Integrated Development Environment; hence, I’ll also call IDE..), you need an IDE. Here is a link of a good IDE. Use this one only. IDE

[To install the IDE, just copy the downloaded file to your C drive. Double click it. It will take care of itself.]

And now, books. For books I would prefer E. Balaguruswamy or Y. Kanitkar.

So, this much for today.. Have a good day..