homecode zoneQuick Codedownloadssubmit codeabout usfeedbackscontact ussitemap
 
Beginners
Intermediate
Proffessional
Array
Array & String
Looping
Branching
Constant Variable & Data type
Operators
Function
Structures & Unions
Pointers
Liabrary
Pro - Languages
C/C++
Java
Visual basic
asp
vb.net 2003/2005
asp.net
Quick Code
SUBMIT CODE
Mail List
LINKS
Submit LINK
 
ProgrammerGuide.net - C-Constant Variable & Data Types.
Home » C/C++ Zone » Constant Variable & Data Types

Constant

Constants in C refer to fixed values that do not change during the execution of a program .C supports several types of constants as illustrated

 
1. Constant  
   

A. Numeric Constant

 

a. Integer Constant

b. Real Constant

B. Character Constant

 

a. Single Character Constant

b. String Constant

Integer Constants

An integer constants refers to a sequence of digits. There are three types of integers, namely, decimal integer ,octal integer and hexadecimal integer.

Decimal integer consist of set of digit ,0 through 9,preceded by an optional - or + sign. Valid examples of decimal integer contents are:

123     -321     0     654321     +78

Embedded spaces, commas and non-digit characters are not permitted between digits. For example.

15     750     20,000     $1000

are illegal numbers. note that ANSI C supports unary plus which was not defined earlier.

037     0     0435     0551

A  sequence of digits preceded by 0x or 0X is considered as hexadecimal integer .They may also include alphabets A through F. The letter A through F represent the number s 10 through15.Following are the examples of  valid hex integers.

0X2     0xpF     0Xbcd     0x

We rarely use octal and hexadecimal numbers in programming.

The largest integer value that can be  stored in machine dependent .It is 32767 on 16-bit  machines and 2,147,483,647 on 32-bit machine. It is also possible to store larger integer constants on these machines by appending qualifiers such as U, L and UL to the constants. For example:

56789U or 56789u (unsigned integer)
987612347UL or 98761234ul (unsigned long integer)
9876543L or 98765431l (long integer)

Example for this constants

Program
     main()
      {
         printf ("Integer values\n\n");
         printf ("%d %d %d\n",32767,32767+1,32767+10);
         printf ("\n");
         printf ("long integer values\n\n");
         printf ("%ld %ld %ld\n",32767L,32767L+1L,32767L+10L);
      }

Output
    
Integer values
     32767 -32768 -32759
     Long integer values
     32767 32768 32777



« Previous 1 2 3 4 5 Next »

Viewers: 16
Visitors:127295
Last Updated on:Sunday, January 17, 2010
Home | About us | Feedback | Contact us | Sitemap
Copyright © 2008 ProgrammerGuide.net. All rights reserved.
This site is best viewed in IE 6.0, Firefox 1.5 and above with screen resolution of 1024 X 768.