CProgramming

C Programming Start

question mark, important, sign-1872665.jpg

OPERATOR

OPERATORS

Generally an operator is a symbol that operates shortens values of variables of same data types and produced a result. An operator operates on variables and perform and action in a program. There are three types of operators as below.

  • Unary Operator
  • Binary Operator
          1. Arithmetic Operators
          2. Relational Operators
          3. Logical Operators
          4. Assignment Operators
          5. Pointers Operators
          6. Special Operators
          7. Bitwise Operators
    • Ternary Operator

 

Unary Operator

 The operators which have only one operand are called Unary Operator. The Unary Operators are:

  • ± : Sign operator
  • ++ : Increment operator
  • – – : Decrement operator
  • & : Address of operator
  • * : Value of address
  • ~ : Complement operator

Increment and decrement operators are unary operators that add or subtract one from their operand, respectively. The increment operator and decrement operators manifest in to two forms as Postfix and Prefix.

  • Post increment and Post decrement:
    1. C++ : Assign the value and increase the value by 1.
    2. C– : Assign the value and decrease the value by 1.

[Here C is deem as a variable]

Example:   If a=5, b=a++ then b=5 and a=6 , If a=5, b=a– then b=5 and a=4

  • Pre increment and Post decrement:
    1. ++C : Increase the value and then assign that value.
    2. – –C : Decrease the value and then assign that value.

[Here C is deem as a variable]

Example:   If a=5, b=++a then b=6 and a=6, If a=5, b=–a then b=4 and a=4

Binary Operator

In mathematics, a binary operation is a calculation involving two operands, so operator which have two operands are called Binary operator. All arithmetical, relational, assignment, logical and bitwise operators are Binary.

Table 1: List of Binary Operators

Sl. No.

Category

Operator

Operation/ Meaning

1

Mathematical

+

Addition

2

Mathematical

Subtraction

3

Mathematical

*

Multiplication

4

Mathematical

/

Division

5

Mathematical

%

Reminder

6

Relational

Greater than

7

Relational

Less than

8

Relational

>=

Greater than equal to

9

Relational

<=

Less than equal to

10

Relational

==

Equal to

11

Relational

!=

Not equal to

12

Bitwise

&

Bitwise And

13

Bitwise

|

Bitwise OR

14

Bitwise

^

Bitwise exclusive OR

15

Bitwise

<< 

Left shift

16

Bitwise

>> 

Right shift

17

Bitwise

~

Bitwise complement

18

Assignment

+=

Addition with assignment

19

Assignment

-=

Subtraction with assignment

20

Assignment

*=

Multiplication with assignment

21

Assignment

/=

Division with assignment

22

Assignment

%=

Reminder with assignment

23

Logical

&&

Logical And

24

Logical

||

Logical OR

25

Logical

!!

Logical NOT

Ternary Operator

The operator which have three operands are called Ternary operator. The ternary operator “?:” earns its name because it’s the only operator to take three operands. It is a conditional operator that provides a shorter syntax for the if..then..else statement. The three parts of it’s are Expression, True part and False Part.

Syntax                       : Condition ? Expression1 : Expression2

Example                    : x>y ? g=x : g=y;

Or                                : g=x>y ? x : y;

 

DATA TYPES IN C

The kind of data that the variable may hold in a programming language is referred to as data types. C provides two types of data:

  1. Primary or Primitive Data type
  2. Secondary or Derived Data type

 

Primary Data type:

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 

 

Secondary Data type:

  • Array
  • Structure
  • Pointer
  • Enum
  • Union, etc.

WHAT IS OPERATOR IN C LANGUAGE

OPERATOR OPERATORS Generally an operator is a symbol that operates shortens values of variables of same data types and produced a result. An operator operates on variables and perform and action in a program. There are three types of operators as below. Unary Operator Binary Operator Arithmetic Operators Relational Operators Logical Operators Assignment Operators Pointers …

WHAT IS OPERATOR IN C LANGUAGE Read More »

question mark, important, sign-1872665.jpg

CONSTANT

 In a program, a name May be assigned to a data item. If it remains the same, throughout the program execution, then we say that the value of name is a constant. Thus, constant (literals) is a value, written into a program instruction that does not change during the execution of a program. There are three types of constants as below:

  • String constant
  • Numeric constant
  • Character constant

String Constant

A string constant or literal is a sequence of alphanumeric characters enclosed in  double quotation marks the maximum length of a string constant is limited to 255 characters. Each string constant is automatically added with a terminating character ‘\0’.Thus the string “abc” will actually be represented as “abc\0” in the memory and its size is 4 characters.

 

Numeric Constant

Numeric constant has a constant value in number. The value of the constant can be positive or negative. There are 4 types of numeric constants as follows.

 

 

  1. Integer Constant: – Integer constants are whole numbers. An integer constant may be either a short integer or long integer.
  2. Floating Point Constant: – A floating point constant has a real value. It may be written in two forms called the fraction form such as 0.3 and the other as exponent form such as 3.7e12.
  3. Octal Constant: – Octal numbers are the integer numbers with a base 8. The digits allowed in this system are 0 to 7.
  4. Hex Constant: – Hex decimal numbers are integer numbers to the base 16. The digits allowed in this system are 0 to 9 and letters A to F.

 

 

Character Constant

Character constant is either a single alphabet or a single digit or a single special symbol enclosed within a pair of single quotation mark, such as ‘A’, ‘a’, ‘.’, ‘?’.

 

 

IDENTIFIERS

IDENTIFIERS

Identifiers are refers to the names of variables, functions and arrays. Identifiers are also the names of objects, which can take different values but only one value at a time. Once a value is assigned to an identifier, it cannot be changed during the execution of the program.

WHAT IS OPERATOR IN C LANGUAGE

OPERATOR OPERATORS Generally an operator is a symbol that operates shortens values of variables of same data types and produced a result. An operator operates on variables and perform and action in a program. There are three types of operators as below. Unary Operator Binary Operator Arithmetic Operators Relational Operators Logical Operators Assignment Operators Pointers …

WHAT IS OPERATOR IN C LANGUAGE Read More »

question mark, important, sign-1872665.jpg

VARIABLES

A quantity or value which may vary during processing of C programming procedure is called variable. Variable is a name that C language compiler associates with a storage location in the main memory of the computer. Variable holds data that can be modified during program execution. After you declare a variable in a program, you can assign it a value. A variable is an identifier that is used to represent some specified type of information within a designated portion of a program.

Rules for Naming a Variable

  1. A variable name is any combination of 1to 10 alphabets. Digits or special symbol (underscore). Some compiler allows variable names whose length could be up to 40 characters. Still it could be safer to strict to the rule of 8 characters.
  2. The first character of the variable must be an alphabet. Don’t use the underscore as the 1st character of variable name.
  3. No comma, blank space or special symbols are allowed.
  4. Keywords are not allowed.
  5. Uppercase and lowercase letters are distinct.

WHAT IS OPERATOR IN C LANGUAGE

OPERATOR OPERATORS Generally an operator is a symbol that operates shortens values of variables of same data types and produced a result. An operator operates on variables and perform and action in a program. There are three types of operators as below. Unary Operator Binary Operator Arithmetic Operators Relational Operators Logical Operators Assignment Operators Pointers …

WHAT IS OPERATOR IN C LANGUAGE Read More »

question mark, important, sign-1872665.jpg
question mark, important, sign-1872665.jpg

KEYWORDS IN C LANGUAGE

Keywords are the basic building blocks for programming statement. These are the words whose meaning has already been explained to the C compiler. Keywords also known as reserve words whose meaning cannot change. All keywords written in lower case and cannot be used as a variable names. There are 32 keywords available in C as listed below:

1.       auto

2.       break

3.       case

4.       char

5.       const

6.       continue

7.       default

8.       do

9.       double

10.   else

11.   enum

12.   extern

13.   float

14.   for

15.   goto

16.   if

17.   int

18.   long

19.   register

20.   return

21.   short

22.   signed

23.   sizeof

24.   static

25.   struct

26.   switch

27.   typedef

28.   union

29.   unsigned

30.   void

31.   volatile

32.   while