Skip to main content

Datatypes

As our English Language is constructed of alphabets,words,sentences and paragraphs.
Similarly in C language a program is constructed using constants,variables and keywords.A character is the most basic element.Any alphabet,number or special symbol is a character.These characters when combined properly form constants,variables and keywords.
A 'constant' is that which never changes its value;while an 'variable' may change its value.

Constants in C programming are divided as
1)Primary Constants
2)Secondary Constants.

1)Primary Constants:
Integer, Real(Floating) and Character are the sub types of Primary constants.
Rules for writing Integer Constants:

a)It must have atleast one digit.
b)It should not contain a decimal point,as its a integer.
c)If theres no sign then a positive sign is assumed.
d)It should not contain any comma or blank space.
e)The range of integer constant is -32768 to 32767.

Ex.
454
-4256

Rules for writing Real Constants:

The real constants are also called as floating constants.
a)It must have at least one digit.
b)It must have a decimal point.
c)Default sign is positive sign.
d)Blank space or commas should not be present.

Ex.
567.65
-343.34

Rules for writing Character Constants:
a)A character constant can be a single alphabet,digit or a special symbol.
But it must be enclosed with single inverted commas.
b)The length of a character constant should be 1.

Ex.
'G'
'5'

2)Secondary Constants:
Array,Pointer,Structure,Union,Enum,etc. are secondary constants.
We'll discuss about secondary constants in some later post.




C provides a standard, minimal set of basic data types. Sometimes these are called "primitive" types. More complex data structures can be built up from these basic types.

Integer Types

The "integral" types in C form a family of integer types. They all behave like integers and can be mixed together and used in similar ways. The differences are due to the different number of bits ("widths") used to implement each type — the wider types can store a greater ranges of values.

char ASCII character at least 8 bits. Pronounced "car". As a practical matter char is basically always a byte which is 8 bits which is enough to store a single ASCII character. 8 bits provides a signed range of -128..127 or an unsigned range is 0..255. char is also required to be the "smallest addressable unit" for the machine — each byte in memory has its own address.

short Small integer — at least 16 bits which provides a signed range of -32768..32767. Typical size is 16 bits. Not used so much.

int Default integer — at least 16 bits, with 32 bits being typical. Defined to be the "most comfortable" size for the computer. If you do not really care about the range for an integer variable, declare it int since that is likely to be an appropriate size (16 or 32 bit) which works well for that machine.

long Large integer — at least 32 bits. Typical size is 32 bits which gives a signed range of about -2 billion ..+2 billion. Some compilers support "long long" for 64 bit ints.

The integer types can be preceded by the qualifier unsigned which disallows representing negative numbers, but doubles the largest positive number representable. For example, a 16 bit implementation of short can store numbers in the range -32768..32767, while unsigned short can store 0..65535. You can think of pointers as being a form of unsigned long on a machine with 4 byte pointers. In my opinion, it’s best to avoid using unsigned unless you really need to. It tends to cause more misunderstandings and problems than it is worth.



Comments

Popular posts from this blog

Turbo C++ for Windows 7 64 bit

 Its a very simple guide to install Turbo C++ on Windows 7 64 bit  operating system. Follow the steps below to install Turbo C++ compiler on your windows 7 ,64 bit operating system. Note - Please let me know whether the process is working for you or if you are getting some kind of error. Step 1) Install the software DOSBOX version 0.73(Search for it in the search bar). Step 2) Create a folder on your C drive, e.g.Turbo; (c:\Turbo\) Step 3) Extract TC into the created folder(e.g. c:\Turbo\);(you can search and download it) Step 4) Run the application DOSBOX 0.73,previously downloaded and installed. Step 5) Type the following commands at the command prompt that will appear, [z]: mount d c:\Turbo\ Following this you will get a message "Drive D is mounted as local directory c:\Turbo\" Step 6) Type d: to shift to d: Step 7) Then type commands mentioned below; cd tc cd bin tc or tc.exe Step 8) In the turbo C++ go to Options\Directories\ Chang

Calculating the average of two numbers using C++

Though this site aims at understanding C language, I am writing a program for you in C++, to have a general idea about C++ too. A program in C++,to calculate the average of two numbers, which are entered by the keyboard while the execution of the program. Try to understand the program; #include &lt iostream &gt using namespace std; int main() {     float num1,num2,average,sum;     cout << "Enter the first number:";     cin >> num1;     cout << "Enter the second number:";     cin >> num2;     sum=num1+num2;     average=sum/2;     cout << "The sum of the two numbers is:"<< sum<<"\n"<<"The average of the two numbers is:" << average; return(0); } Explaination: The new file header used here in this C++ program is the #include . By this , we are asking the preprocessor to add the contents of the iostream file to our program. The program is written in the

Finding the arithmetic operators

Below is a very simple program to find the arithmetic operator. Please feel free to put a comment if need an explanation. #include #include void main()   {     float a1,a2;     char operator;     printf("\n Enter the values of a1 operator a2\n");     scanf("%f%c%f",&a1,&operator,&a2);     switch(operator)      { case '+': printf("%.2f",a1+a2); break; case '-':  printf("%.2f",a1-a2);  break; case '*':  printf("%.2f",a1*a2); break; case '/':  if(a2==0)  printf("error\n");  else  printf("%.2f",a1/a2);  break; default: printf("unknown operatotr\n"); break;      }    }