Welcome to pickSourcecode.com Login | Register    
pickZy.com
 Home  | search  | games  | General  | C  | C++  | Java  | Php  | Networking  | Visual Basic  | VC++  | Win32  | MFC  | JavaScript  | Jobs  | JavaScript  | Post jobs
C - Constants, string constants, integer constants, character constants, enum       Share
2007-08-29 |  RatheeshTR  | Viewed: 384  |    0

Integer Constants:

The Standard has now invented a new way of working out what type an integer constant is. In the old days, if the constant was too big for an int, it got promoted to a long (without warning). Now, the rule is that a plain decimal constant will be fitted into the first in this list

int   long   unsigned long

that can hold the value.

Plain octal or hexadecimal constants will use this list

int   unsigned int   long   unsigned long

If the constant is suffixed by u or U:

unsigned int   unsigned long

If it is suffixed by l or L:

long   unsigned long

String Constants:

String constants are sequences of characters enclosed in double quotes. The same backslash sequences that are used in character constants can be used in string constants.

E.g., "hello there", "a newline: \n", "a string\nwith multiple\nlines".

If a string is long and you want to break it up across several lines of code, you can put a backslash just before a (real) newline and the C compiler will throw away both the backslash and the newline, e.g.,

    printf ("A very long help message \n that is more readable if it is broken up over \n \
                    several lines.      \n
");

this string contains one real newline (the \n).

Character Constants:

A character constant is a character enclosed in single quotes, e.g., 'a', '2', '.'. Remember that in C, characters are small integers, so you can use a character constant anywhere you can use an integer constant and vise versa

Sequence Represents
\a audible alarm
\b backspace
\f form feed
\n newline
\r carriage return
\t tab
\v vertical tab
\\ backslash
\' quote
\" double quote
\? question mark

The enum statement:

ENUM is closely related to the #define preprocessor.

It allows you to define a list of aliases which represent integer numbers. For example if you find yourself coding something like:

        #define MON 1 
#define TUE 2
#define WED 3
You could use enum as below.
        enum week { Mon=1, Tue, Wed, Thu, Fri Sat, Sun} days;
or
enum escapes { BELL = '\a', BACKSPACE = '\b', HTAB = '\t',
RETURN = '\r', NEWLINE = '\n', VTAB = '\v' };

or
enum boolean { FALSE = 0, TRUE };
An advantage of enum over #define is that it has scope This means that the variable (just like any other) is only visable within the block it was declared within.

eg, program:

1. enum sample program


Latest topics
C - Arrays of structures  Viewed: 285
C - structures and functions  Viewed: 292
tcpdump by host name or ip  Viewed: 292
C - For loop statements  Viewed: 295
C - pointers and Arrays  Viewed: 295
C - File Access  Viewed: 295
C - pointers to pointers  Viewed: 296
C - Register variables  Viewed: 297
C - Static variables  Viewed: 299
C - Pass-by-reference parameters  Viewed: 300

Comments:





Submit comment's

Type:

User Comment's:

Submitted By:
Prof: Software Engineer
Tech: C ,Cpp
Send Mail: ratheesh



Related topics
C - Functions and program structure, Programmed pass-by-reference via pointers, Pass-by-reference parameters
C - Pass-by-reference parameters
C - pass-by-reference via pointers

Related References
c - swap num, pass-by-reference parameters
c - pass-by-reference via pointers

Web site contents © Copyright 2007, All rights reserved.
Help | Terms and Conditions | Privacy Policy | About Us