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 - Fundamental data types:       Share
2007-08-29 |  RatheeshTR  | Viewed: 401  |    1


Variable Names:

There are some restrictions on the names of variables and symbolic constants. names are made up of letters and digits the first character must be a letter. The underscore "_" counts as a letter it is sometimes useful for improving the readability of long varaible names.

Examples of legal variable names include

x         	 result         	outfile          bestyet
x1 x2 out_file best_yet
power impetus gamma hi_score

Fundamental data types:

C has a concept of 'data types' which are used to define a variable before its use.

The definition of a variable will assign storage for the variable and define the type of data that will be held in the location.

Name Description Size* Range*
char Character or small integer. 1byte signed: -128 to 127
unsigned: 0 to 255
short int (short) Short Integer. 2bytes signed: -32768 to 32767
unsigned: 0 to 65535
int Integer. 4bytes
signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
long int (long) Long integer. 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
bool Boolean value. It can take one of two values: true or false. 1byte true or false
float Floating point number. 4bytes 3.4e +/- 38 (7 digits)
double Double precision floating point number. 8bytes 1.7e +/- 308 (15 digits)
long double Long double precision floating point number. 8bytes font size="2" face="Arial">1.7e +/- 308 (15 digits)
wchar_t Wide character. 2bytes 1 wide character


The word int can be omitted in such declarations and typically 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 32 bits, and int either 16 or 32 bits. Each compiler is free to choose appro
short
int samp;
long int count;

The word int can be omitted in such declarations and typically 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 32 bits, and int either 16 or 32 bits. Each compiler is free to choose appropriate sizes for its either 16 or 32 bits

Some data type Samples:

int - data type:

int Count;
Count = 5;

float - data type:

float avg;
avg = 5.6;

double - data type:

double Atoms;
Atoms = 2500000;

char - data type


char Letter;
Letter = 'x';

Modifiers:

* short
* long
* signed
* unsigned

The modifiers define the amount of storage allocated to the variable.
The amount of storage allocated is not cast in stone.

Qualifiers:

* const
* volatile

The const qualifier is used to tell C that the variable value can not change after initialisation.

eg,

const float pi=3.14159;

pi cannot be changed at a later time within the program.
Another way to define constants is with the #define preprocessor

eg,

#define pi 3.14159;

sample program:

#include

int main ()
{
// declaring variables:
int a, b;
int result;

// process:
a = 5;
b = 2;
a = a + 1;
result = a - b;

// print out the result:
printf("%d", result);

// terminate the program:
return 0;
}

To cast, casting:


If you want to change the datatype of a variable you have to use a technic called cast.
For example if want to change an int to a float you could use the following syntax:

var2 = (float)var1;

#include

int main()
{
int var1;
float var2;

var2 = (float)var1;
}


Latest topics
C - Arrays of structures  Viewed: 285
C - structures and functions  Viewed: 292
tcpdump by host name or ip  Viewed: 292
C - pointers and Arrays  Viewed: 295
C - File Access  Viewed: 295
C - For loop statements  Viewed: 296
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