C LANGUAGE GENERAL TERM
Variable
A variable is used to hold data within your program. A variable represents a location in your computer's memory. You can put data into this location and retrieve data out of it. Every variable has two parts, a name and a data type.Variable Names
- Valid names can consist of letters, numbers and the underscore
- The first character must not start with a number.
- A variable name may not be a C keyword.
- Variable names are case sensitive. So, Age, AGE, aGE and AgE could be names for different variables
- No special symbols other than underscore (such as fourth_Dimension).
Keyword
Keywords are reserved identifier and they can not be used as names for the program variables or other user defined program elements. The meanings of the keywords have already been given to the compiler. The keywords are also called reserved words.List of C Keywords
auto | double | if | static |
break | else | int | struct |
case | enum | long | switch |
char | extern | near | typedef |
const | float | register | union |
continue | far | return | unsigned |
default | for | short | void |
do | goto | signed | while |
Data Types
C provides built in data types for character, float and integer data. As an aside, in C you may assign a value to a variable when you declare it.Integer variables
Integer variables are used to store whole numbers. There are several keywords used to declare integer variables, including int, short, long, unsigned short, unsigned long. The difference deals with the number of bytes used to store the variable in memory, long vs. short, or whether negative and positive numbers may be stored, signed vs. unsigned. These differences will be explained in more advanced tutorials. For now, use int to declare integer variables. On most 32-bit systems, int is synonymous with signed long.Examples:
int count;
int number_of_students = 30;
Float variables
Float variables are used to store floating point numbers. Floating point numbers may contain both a whole and fractional part, for example, 52.7 or 3.33333333. There are several keywords used to declare floating point numbers in C including float, double and long double. The difference here is the number of bytes used to store the variable in memory. Double allows larger values than float. Long double allows even larger values. These differences will be explained in more advanced tutorials. For now, use float to declare floating point variables.Examples:
float owned = 0.0;
float owed = 1234567.89;
Character variables
Character variables are used to store character values. The use of characters and strings will be covered in a latter tutorial. Character variables are declared with the keyword char.Examples:
char firstInitial = 'J';
char secondInitial = 'K';
Datatypes in C
Data Type | Category | Range | Bytes | Format |
Character | signed char | -128 to +127 | 1 | %c |
unsigned char | 0 to 255 | 1 | %c | |
Integer | short signed int | -32768 to +32767 | 2 | %d |
short unsigned int | 0 to 65535 | 2 | %u | |
signed int | -32768 to +32767 | 2 | %d | |
unsigned int | 0 to 65535 | 2 | %u | |
long signed int | -2147483648 to +2147483647 | 4 | %ld | |
long unsigned int | 0 to 4294967295 | 4 | %lu | |
Float | float | -3.4e38 to +3.4e38 | 4 | %f |
Double | double | -1.7e308 to +1.7e308 | 8 | %lf |
long double | -1.7e4932 to +1.7e4932 | 10 | %Lf |
2 comments:
nice blog- for IT students- once take a look of Answering Machine
Post a Comment