marq

Dr. Charles Simonyi is the Father of Modern Microsoft Excel                                           JavaScript was originally developed by Brendan Eich of Netscape under the name Mocha, later LiveScript, and finally renamed to JavaScript.                                           The word "Biology" is firstly used by Lamarck and Treviranus                                           Hippocrates (460-370 bc) is known as father of medicine.                                           Galene, 130-200 is known as father of Experimental Physology                                           Aristotle (384-322 BC) is known as Father of Zoology because he wrote the construction and behavior of different animals in his book "Historia animalium"                                           Theophrastus(370-285 BC) is known as father of Botany because he wrote about 500 different plants in his book "Historia Plantarum".                                           John Resig is known as Father of Jquery -                                          HTML is a markup language which is use to design web pages. It was invented in 1990 by Tim Berners-Lee.                                                                The Google was founded by Larry Page and Sergey Brin.                                                                Rasmus Lerdorf was the original creator of PHP. It was first released in 1995.                                                               Facebook was founded by Mark Zuckerberg                                                               Bjarne Stroustrup, creator of C++.                                                                Dennis Ritchie creator of C                                                                                                                              James Gosling, also known as the "Father of Java"                                          At 11.44%, Bihar is India's fastest growing state                                          Father of HTML -Tim Berners Lee                                          orkut was created by Orkut Büyükkökten, a Turkish software engineer                    Photoshop: It came about after Thomas Knoll, a PhD student at the University of Michigan created a program to display grayscale images on a monochrome monitor which at the time was called 'Display'.

c data type and operator


C Character-Set Table
Letters
Digits

Upper Case A to Z
0 to 9

Lower Case a to z
.



Special Characters


,        Comma
&     Ampersand
.         Period
^       Caret
;        Semicolon
*      Asterisk
:        Colon
-       Minus Sign
?       Question Mark
+       Plus Sign

'
Aphostrophe
< .Opening Angle (Less than sign) " .Quotation Marks >
.Closing Angle (Greater than sign)

!            .Exclaimation Mark
(          .Left Parenthesis

|    .Vertical Bar
)     .Right Parenthesis

/     .Slash
[      .Left Bracket

\     .Backslash
]     .Right Bracket

~      .Tilde
{        Left Brace

-        Underscore
}        Right Bracket

$        Dollar Sign
#        Number Sign

%      Percentage Sign



White Space
1. Blank Space
2. Horizontal Tab
3. Carriage Return
4. New Line
5. Form Feed
Every word in C language is a keyword or an identifier. Keywords in C language cannot be used as a variable name. They are specifically used by the compiler for its own purpose and they serve as building blocks of a c program.


The following are the Keyword set of C language.


.auto .else .register .union
.break .enum .return .unsigned
.case .extern .short .void
.char .float .signed .volatile
.const .for .size of .while
.continue .goto .static .
.default .if .struct .
.do .int .switch .
.double .long .typedef .


some compilers may have additional keywords listed in C manual.


Identifiers refers to the name of user-defined variables, array and functions. A variable should be essentially a sequence of letters and or digits and the variable name should begin with a character.


Both uppercase and lowercase letters are permitted. The underscore character is also permitted in identifiers.
he identifiers must conform to the following rules.


1. First character must be an alphabet (or underscore)
2. Identifier names must consists of only letters, digits and underscore.
3. A identifier name should have less than 31 characters.
4. Any standard C language keyword cannot be used as a variable name.
5. A identifier should not contain a space.


Constants
A constant value is the one which does not change during the execution of a program. C supports several types of constants.


1. Integer Constants
2. Real Constants
3. Single Character Constants
4. String Constants


Integer Constants
An integer constant is a sequence of digits. There are 3 types of integers namely decimal integer, octal integers and hexadecimal integer.


Decimal Integers consists of a set of digits 0 to 9 preceded by an optional + or - sign. Spaces, commas and non digit characters are not permitted between digits. Example for valid decimal integer constants are


123
-31
0
562321
+ 78


Some examples for invalid integer constants are


15 750
20,000
Rs. 1000


Octal Integers constant consists of any combination of digits from 0 through 7 with a O at the beginning. Some examples of octal integers are


O26
O
O347
O676


Hexadecimal integer constant is preceded by OX or Ox, they may contain alphabets from A to F or a to f. The alphabets A to F refers to 10 to 15 in decimal digits. Example of valid hexadecimal integers are


OX2
OX8C
OXbcd
Ox

Real Constants
Real Constants consists of a fractional part in their representation. Integer constants are inadequate to represent quantities that vary continuously. These quantities are represented by numbers containing fractional parts like 26.082. Example of real constants are


0.0026
-0.97
435.29
+487.0


Real Numbers can also be represented by exponential notation. The general form for exponential notation is mantissa exponent. The mantissa is either a real number expressed in decimal notation or an integer. The exponent is an integer number with an optional plus or minus sign.
A Single Character constant represent a single character which is enclosed in a pair of quotation symbols.


Example for character constants are


'5'
'x'
';'
' '


All character constants have an equivalent integer value which are called ASCII Values.

String Constants
A string constant is a set of characters enclosed in double quotation marks. The characters in a string constant sequence may be a alphabet, number, special character and blank space. Example of string constants are


"VISHAL"
"1234"
"God Bless"
"!.....?"

Backslash Character Constants [Escape Sequences]
Backslash character constants are special characters used in output functions. Although they contain two characters they represent only one character. Given below is the table of escape sequence and their meanings.


Constant
Meaning

'\a'
.Audible Alert (Bell)
'\b'
.Backspace

'\f' .Formfeed
'\n' .New Line
'\r' .Carriage Return
'\t' .Horizontal tab
'\v' .Vertical Tab
'\'' .Single Quote
'\"' .Double Quote
'\?' .Question Mark
'\\' .Back Slash
'\0' .Null


DATA TYPE
A C language programmer has to tell the system before-hand, the type of numbers or characters he is using in his program. These are data types. There are many data types in C language. A C programmerhas to use appropriate data type as per his requirement.

C language data types can be broadly classified as
Primary data type
Derived data type
User-defined data type

Primary data type
All C Compilers accept the following fundamental data types


1. Integer                                        int

2. Character                                   char

3. Floating Point                             float

4.Double precision floating point    double

5. Void                                          void



The size and range of each data type is given in the table below


DATA TYPE          RANGE OF VALUES

char                       -128 to 127

Int                        -32768 to +32767

float                     3.4 e-38 to 3.4 e+38

double                 1.7 e-308 to 1.7 e+308


Integer Type :
Integers are whole numbers with a machine dependent range of values. A good programming language as to support the programmer by giving a control on a range of numbers and storage space. C has 3 classes of integer storage namely short int, int and long int. All of these data types have signed and unsigned forms. A short int requires half the space than normal integer values. Unsigned numbers are always positive and consume all the bits for the magnitude of the number. The long and unsigned integers are used to declare a longer range of values.

Floating Point Types :
Floating point number represents a real number with 6 digits precision. Floating point numbers are denoted by the keyword float. When the accuracy of the floating point number is insufficient, we can use the double to define the number. The double is same as float but with longer precision. To extend the precision further we can use long double which consumes 80 bits of memory space.

void Type :
Using void data type, we can specify the type of a function. It is a good practice to avoid functions that does not return any values to the calling function.

Character Type :
A single character can be defined as a defined as a character type of data. Characters are usually stored in 8 bits of internal storage. The qualifier signed or unsigned can be explicitly applied to char. While unsigned characters have values between 0 and 255, signed characters have values from –128 to 127.

Size and Range of Data Types on 16 bit machine.


TYPE                             SIZE (Bits)                                Range

Char or Signed Char        8                                         -128 to 127

Unsigned Char                 8                                          0 to 255

Int or Signed int               16                                       -32768 to 32767

Unsigned int                    16                                         0 to 65535

Short int or Signed short int   8                                     -128 to 127

Unsigned short int               8                                       0 to 255

Long int or signed long int    32                                     -2147483648 to 2147483647

Unsigned long int                 32                                      0 to 4294967295

Float                                  32                                      3.4 e-38 to 3.4 e+38

Double                             64                                        1.7e-308 to 1.7e+308

Long Double                    80                                        3.4 e-4932 to 3.4 e+4932


Declaration of Variables
Every variable used in the program should be declared to the compiler. The declaration does two things.
1. Tells the compiler the variables name.
2. Specifies what type of data the variable will hold.

The general format of any declaration

datatype v1, v2, v3, ……….. vn;

Where v1, v2, v3 are variable names. Variables are separated by commas. A declaration statement must end with a semicolon.

Example:

int sum;
int number, salary;
double average, mean;


Datatype Keyword Equivalent

Character                                 char

Unsigned Character                  unsigned char

Signed Character                      signed char

Signed Integer                           signed int (or) int

Signed Short Integer                 signed short int (or) short int (or) short

Signed Long Integer                 signed long int (or) long int (or) long

UnSigned Integer                                                   unsigned int (or) unsigned

UnSigned Short Integer                                         unsigned short int (or) unsigned short

UnSigned Long Integer                                         unsigned long int (or) unsigned long

Floating Point                                                       float

Double Precision Floating Point                           double

Extended Double Precision Floating Point            long double


User defined type declaration
In C language a user can define an identifier that represents an existing data type. The user defined datatype identifier can later be used to declare variables. The general syntax is

typedef type identifier;

here type represents existing data type and ‘identifier’ refers to the ‘row’ name given to the data type.

Example:

typedef int salary;
typedef float average;

Here salary symbolizes int and average symbolizes float. They can be later used to declare variables as follows:

Units dept1, dept2;
Average section1, section2;

Therefore dept1 and dept2 are indirectly declared as integer datatype and section1 and section2 are indirectly float data type.

The second type of user defined datatype is enumerated data type which is defined as follows.

Enum identifier {value1, value2 …. Value n};

The identifier is a user defined enumerated datatype which can be used to declare variables that have one of the values enclosed within the braces. After the definition we can declare variables to be of this ‘new’ type as below.

enum identifier V1, V2, V3, ……… Vn

The enumerated variables V1, V2, ….. Vn can have only one of the values value1, value2 ….. value n

Example:

enum day {Monday, Tuesday, …. Sunday};
enum day week_st, week end;
week_st = Monday;
week_end = Friday;
if(wk_st == Tuesday)
week_en = Saturday;

Declaration of Storage Class
Variables in C have not only the data type but also storage class that provides information about their location and visibility. The storage class divides the portion of the program within which the variables are recognized.

auto : It is a local variable known only to the function in which it is declared. Auto is the default storage class.

static : Local variable which exists and retains its value even after the control is transferred to the calling function.

extern : Global variable known to all functions in the file

register : Social variables which are stored in the register.

Defining Symbolic Constants
A symbolic constant value can be defined as a preprocessor statement and used in the program as any other constant value. The general form of a symbolic constant is

# define symbolic_name value of constant
Valid examples of constant definitions are :

# define marks 100
# define total 50
# define pi 3.14159

These values may appear anywhere in the program, but must come before it is referenced in the program.


It is a standard practice to place them at the beginning of the program.

Declaring Variable as Constant
The values of some variable may be required to remain constant through-out the program. We can do this by using the qualifier const at the time of initialization.

Example:
Const int class_size = 40;


The const data type qualifier tells the compiler that the value of the int variable class_size may not be modified in the program.

Sponsored Links

Volatile Variable
A volatile variable is the one whose values may be changed at any time by some external sources.


Example:
volatile int num;

The value of data may be altered by some external factor, even if it does not appear on the left hand side of the assignment statement. When we declare a variable as volatile the compiler will examine the value of the variable each time it is encountered to see if an external factor has changed the value.
C Programming - Operators

In this tutorial you will learn about Operators, Arithmetic operators, Relational Operators, Logical Operators, Assignment Operators, Increments and Decrement Operators, Conditional Operators, Bitwise Operators and Special Operators.

Operators Introduction
An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C language program to operate on data and variables. C has a rich set of operators which can be classified as


1. Arithmetic operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Increments and Decrement Operators
6. Conditional Operators
7. Bitwise Operators
8. Special Operators

1. Arithmetic Operators
All the basic arithmetic operations can be carried out in C. All the operators have almost the same meaning as in other languages. Both unary and binary operations are available in C language. Unary operations operate on a singe operand, therefore the number 5 when operated by unary – will have the value –5.

Arithmetic Operators
Operator
Meaning

+ Addition or Unary Plus

– Subtraction or Unary Minus

* Multiplication

/ Division

% Modulus Operator



Examples of arithmetic operators are

x + y
x - y
-x + y
a * b + c
-a * b etc.,

here a, b, c, x, y are known as operands. The modulus operator is a special operator in C language which evaluates the remainder of the operands after division.

Example
.
#include                                                //include header file stdio.h
void main()                                           //tell the compiler the start of the program
{
int numb1, num2, sum, sub, mul, div, mod;     //declaration of variables
scanf (“%d %d”, &num1, &num2);               //inputs the operands
sum = num1+num2;                                      //addition of numbers and storing in sum.
printf(“\n Thu sum is = %d”, sum);                 //display the output

sub = num1-num2;                                     //subtraction of numbers and storing in sub.
printf(“\n Thu difference is = %d”, sub);     //display the output

mul = num1*num2; //multiplication of numbers and storing in mul.
printf(“\n Thu product is = %d”, mul);          //display the output

div = num1/num2; //division of numbers and storing in div.
printf(“\n Thu division is = %d”, div);            //display the output

mod = num1%num2; //modulus of numbers and storing in mod.
printf(“\n Thu modulus is = %d”, mod);           //display the output
}
.

Integer Arithmetic
When an arithmetic operation is performed on two whole numbers or integers than such an operation is called as integer arithmetic. It always gives an integer as the result. Let x = 27 and y = 5 be 2 integer numbers. Then the integer operation leads to the following results.

x + y = 32
x – y = 22
x * y = 115
x % y = 2
x / y = 5

In integer division the fractional part is truncated.

Floating point arithmetic
When an arithmetic operation is preformed on two real numbers or fraction numbers such an operation is called floating point arithmetic. The floating point results can be truncated according to the properties requirement. The remainder operator is not applicable for floating point arithmetic operands.

Let x = 14.0 and y = 4.0 then

x + y = 18.0
x – y = 10.0
x * y = 56.0
x / y = 3.50

Mixed mode arithmetic
When one of the operand is real and other is an integer and if the arithmetic operation is carried out on these 2 operands then it is called as mixed mode arithmetic. If any one operand is of real type then theresult will always be real thus 15/10.0 = 1.5

2. Relational Operators
Often it is required to compare the relationship between operands and bring out a decision and program accordingly. This is when the relational operator come into picture. C supports the following relational operators.


Operator  Meaning

< is less than              
<= is less than or equal to
>  is greater than

>= is greater than or equal to

== is equal to

!= is not equal to

It is required to compare the marks of 2 students, salary of 2 persons, we can compare them usingrelational operators.

A simple relational expression contains only one relational operator and takes the following form.

exp1 relational operator exp2

Where exp1 and exp2 are expressions, which may be simple constants, variables or combination of them. Given below is a list of examples of relational expressions and evaluated values.

6.5 <= 25 TRUE -65 > 0 FALSE
10 < 7 + 5 TRUE Relational expressions are used in decision making statements of C language such as if, while and forstatements to decide the course of action of a running program. 3. Logical Operators C has the following logical operators, they compare or evaluate logical and relational expressions. Operator Meaning && Logical AND || Logical OR ! Logical NOT Logical AND (&&) This operator is used to evaluate 2 conditions or expressions with relational operators simultaneously. If both the expressions to the left and to the right of the logical operator is true then the whole compound expression is true. Example a > b && x = = 10

The expression to the left is a > b and that on the right is x == 10 the whole expression is true only if both expressions are true i.e., if a is greater than b and x is equal to 10.

Logical OR (||)
The logical OR is used to combine 2 expressions or the condition evaluates to true if any one of the 2 expressions is true.

Example


a < m || a < n The expression evaluates to true if any one of them is true or if both of them are true. It evaluates to true if a is less than either m or n and when a is less than both m and n. Logical NOT (!) The logical not operator takes single expression and evaluates to true if the expression is false and evaluates to false if the expression is true. In other words it just reverses the value of the expression. For example ! (x >= y) the NOT expression evaluates to true only if the value of x is neither greater than or equal to y

4. Assignment Operators
The Assignment Operator evaluates an expression on the right of the expression and substitutes it to the value or variable on the left of the expression.

Example
x = a + b


Here the value of a + b is evaluated and substituted to the variable x.

In addition, C has a set of shorthand assignment operators of the form.


var oper = exp;

Here var is a variable, exp is an expression and oper is a C binary arithmetic operator. The operatoroper = is known as shorthand assignment operator

Example

x + = 1 is same as x = x + 1


The commonly used shorthand assignment operators are as follows

Shorthand assignment operators


Statement with simple
assignment operator
Statement with
shorthand operator

a = a + 1
a += 1

a = a – 1
a -= 1

a = a * (n+1)
a *= (n+1)

a = a / (n+1)
a /= (n+1)

a = a % b
a %= b

Example for using shorthand assignment operator
.
#define N 100 //creates a variable N with constant value 100
#define A 2 //creates a variable A with constant value 2

main()          //start of the program
{
int a;             //variable a declaration
a = A;            //assigns value 2 to a

while (a < N)                            //while value of a is less than N
 {                                             //evaluate or do the following
printf(“%d \n”,a);                      //print the current value of a
a *= a;                                     //shorthand form of a = a * a }
//end of the loop }                    //end of the program .

 Output 2 4 16            

No comments:

Post a Comment