Pages

Thursday, 25 February 2016

Data Type in C

Data type is used to declare  type of variable in C Programming. Because Data Type is very important if we want make variable.

First condition in order to make variable is user must know about data. Its mean programmer have knowledge about type of data programmer wants store into variable and then program make variable according to its receiving value.

Now we try :-

Any one say make a program in C to add to values and print result into screen.

But in above program we recognized that values are number but C compiler approved two type of number that are a number without decimal and another number with decimal point.

Then here a question arise which type of data is comming? Then programmer will clear to person about type of number.

Ok after conversation we have no doubt  about variable's data type and we can declare our data. In C we use a keyword to represent data type that are given below

if we want declare none decimal number it called integer and in C has reserved key for integer that written by "int". int is symbolic name of Integer. similarly for Floating values can declare y using keyword/reserved word that is "float"

for integer value

int number1 = 12;

for floating values

float number1 = 12.00;

There are basically four type of data types that are given below -

1)  - Basic Types or Fundamental types.

2) - Enumerated types

3) - Void Types

4) - Derived Types.



Basic Data Types : - In C there are three basic fundamental types of data are existed namely integer (int), Character (char), floating point (float).

Integer Type :-  Integer are whole Numbers, that use for non decimal number it has range of value supported by particular machine. Generally three range of integer are exist in C which are "short int" , "int" and "long ing" 

short int comes in two type 

(a) - unsigned short int : this type of int we use when our input range between -128 to 127

(b) - signed short int : We use this type of integer when we require to take input that range vary between 0 to 255.

now second type of integer is "int" that come also in two type "signed int" and "unsigned int" whose range are -32768 to 32767 and 0 to 65535 respectively.

 now similarly all fundamental variables have different different range according to its use.

Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295


 Floating Point 

Type Storage size Value range Precision
float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
double 8 byte 2.3E-308 to 1.7E+308 15 decimal places
long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places

 

Friday, 19 February 2016

Constants in C Programming Language



Constant is a quantity in C whose value does not change ever. This quantity stored in memory at any certain location of Computer. There are mostly two type of constant which are given below.

  1. Primary Constant
  2. Secondary Constant

These constant are further categorized as shown in figure

But at this stage our focus will we on Primary Constants, namely  Numeric and Character Constants.

Rules For Constructing Integers Constants

An integer constant means a sequence of digit. There are three type of Integer constant which are decimal integers, octal integer and hexadecimal integer.  

Decimal integers contain digit from 0 to 9 with optional sign – or + which indicate that number is positive or negative.  Valid set of decimal integers are 


+ 123, 123, 456, -34, -542, 0, 76543

While space, commas, and non-digit characters are not entertained between digits. For example –

15-234, 23,000, 43 434, $3454

are illegal numbers.


  1. An integer constant must at least one digit.
  2. Decimal point must not be allowed
  3. Number could be positive or negative.
  4. If no sign used before number, it means integer Constant assumed to be positive.
  5. No comma, blank space, and dollar sign must within or before an integer constant.


Integer Constant have range limitation which vary according machine. If you working 16 bit computer , integer constant range will vary between -32768 to +32767

Rules For Constructing Real Constants

Integer constant are unable to calculate measurement problem and cost estimated problem because these quantities are represented  by number containing fraction part like 13.456. this numbers are called real number or floating points number

For example –

23.54554, -544534.56546, +45345.5534

Floating points number or real Constant are those number that contain decimal points between digits but remember point will be between digit not before neither after like .43 or 4343.

Valid
Invalid
443.4434, -434.546, +55.54
.4545, -.5345, 45354. , -53454.

  1.  A real number must be at least  two digit with one decimal point.
  2. It could be either positive or negative.
  3. Default sign assumed positive.
  4. No comma, blank space are allowed between number except decimal point.


There are another way to represent real number is exponential notation or scientific notation. In this type of notation two part exist that joined with e character. Like 32.334e2

First part of this notation is called mantissa and second part of this notation called exponent. This method of real number we will descius in last chapter.

Rules For Constructing Character Constants

Character constant is a single character from character set of C that enclosed by single quote marks. Examples of character constant are
‘5’           ‘a’           ‘;’            ‘ ’

Maximum length of character constant must be 1 with enclosed by single quote.

Above ‘5’ is character constant and it is not equal to 5 because 5 is digit and ‘5’ is character constant.  Every character constants have integer value known as ASCII values. ‘5’ integer value is 53 and integer value of ‘a’ is 97.

There are many discussion are remaining on this section we will later in Next related Section

Rules for Constructing String Constant

A string constant is sequence of character that enclosed by double quotes. This character may be numbers, alphabets and special symbols and also blank space. Example are


“How are you”                  “1988”                   “WELL DONE”                    “? $%^%$#”                       “3+4=7”

There you should mind that character constant is not equivalent to string constant example (“x” is not equivalent to ‘x’)


  1. String Constant should be enclosed with double quotes.
  2. String Constant contains all digit, special symbols and alphabets.
  3. String constant contain blank space.


Backslash Character Constants

There is special character constants that used with output function in C. every Backslash character constant used with specific reason during outputting. For example, the symbol ‘\n’ stands here for newline character that tells signal to computer print new line after this ‘\n’ new line symbol.

Identifiers in C programming and C Tutorials

Identifiers is nothing but the name of Variables, Functions and Arrays. when we make any variable and function we should have to give name to them and these name are called Identifiers

There  are some rules to use Identifiers which are given below.

  1.  When programmer make identifiers they must include alphabet in first place of Identifiers like a123, num2, 
  2. If you use 12a, #ahe, $abc etc are invalid Identifiers.
  3. Programmer can use '_' in first place in Identifiers like _num, _stdname.
  4. Programmer must aware to use of white space because white space can't use in identifiers.
  5. Cannot use Keywords.
  6. Length of Identifiers carry 1 to 31 characters but maximum 8 character length of Identifiers is good to programming skill.

Keywords in C

Keywords

In C language, keyword is a word/unit that made by combination of alphabet and reserved by compiler. its mean programmer can't use these word as variable name and function name. these Keyword used by programmer in program for perform specific task and every Keywords have special meaning in C language.

Like

Here "int" is Keyword that use in program to declare a variable and its type.

Example: int num1;

Now what is meaning of above line?

As we said "int" is keyword that used to declare variable and its type. In above example there is a word num1 that is declared as a variable and int is written before num1 tell to compiler that type of num1 variable is integer.

Programmer should remember this that we can not use "int" as variable's name and function's name.

There are 32 keyword in C language that are given below. Each Keywords have special meaning and special use for certain area of program.

autodoubleintstruct
breakelselongswitch
caseenumregistertypedef
charexternreturnunion
constfloatshortunsigned
continueforsignedvoid
defaultgotosizeofvolatile
doifstaticwhile

Keywords serve as basic building blocks for program statements. All these keyword are explained in next related chapter.

Thursday, 18 February 2016

C Token

सी टोकेन

अँग्रेजी का एक वाक्य देखे तो हम पाएंगे की उस वाक्य को बनाने के लिए कुछ शब्द और हलंत चिन्ह (punctuation marks) का प्रयोग किया जाता हैं। इन शब्दो और हलंत चिन्हो (punctuation mark) को अँग्रेजी व्याकरण (ग्रामर) मे टोकन्स कहते हैं। ठीक इसी प्रकार सी भाषा मे कुछ ऐसी इकाई हैं जिनहे सही क्रम मे आपस मे मिलने से प्रोग्राम का निर्माण होता हैं। ऐसे इकाई को सी टोकन्स कहते हैं। लेकिन अँग्रेजी की तरह सी मे दो टोकन्स नहीं होते बल्कि 6 टोकन्स होते हैं। इन्ही टोकन्स को जब सी के सिंटेक्स के आधार पर क्रमबद्ध करते हैं तो सी भाषा का निर्माण होता हैं। नीचे दिये चित्र मे आप सी टोकन्स को देख सकते हैं।
 
इन 6 टोकन के सही जोड़ (combination) से इन्सट्रक्शन का निर्माण होता हैं और इन्सट्रक्शन के जोड़ से प्रोग्राम का निर्माण होता हैं।

Keywords in given Program

ऊपर दिये चित्र मे सी प्रोग्राम बना हैं जिसमे घेरा लगाया गया हैं, जिनमे घेरा लगे हैं वह कीवर्ड / keyword कहलाते हैं।


Identifiers in given Program

ऊपर दिये प्रोग्राम मे घेरे से दर्शाये गए इकाई इडेंटिफ़ायर्स / identifiers कहलाते हैं।


Constants in given Program

ऊपर दिये प्रोग्राम मे घेरे से दर्शाये गए इकाई कंसटेंट / Constant कहलाते हैं।


Operator in given Program

ऊपर दिये प्रोग्राम मे घेरे से दर्शाये गए इकाई आपरेटर / Operators कहलाते हैं।


Special Symbols in given Program

ऊपर दिये प्रोग्राम मे घेरे से दर्शाये गए इकाई स्पेशल सिंबल / Special Symbol कहलाते हैं।


Strings in given Program


ऊपर दिये प्रोग्राम मे घेरे से दर्शाये गए इकाई स्ट्रिंग / String कहलाते हैं।


Popular Posts