Tuesday, 28 March 2017

operator in c | How to use operator in c language

Operators are the symbols which instruct compiler about which operation will perform in this line of code.There are eight categories in Operators C.

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

Arithmetic Operators :


An arithmetic operator plays mathematical operations which include addition, subtraction and multiplication on numerical values (constants and variables).

 Operator        Meaning of Operator
+addition or unary plus (Use when we add two or more then two numbers)
-subtraction or unary minus (Use when we Subtract two or more then two numbers)
*multiplication (Use when we Multiply two or more then two numbers)
/division (Use when we divide two or more then two numbers)
%remainder after division(when we need to find remainder) 

Relational Operators :

A relational operator checks the relationship among  operands. If the relation is proper, it returns 1; if the relation is fake, it returns zero.

OperatorMeaning of OperatorExample
==Equal toWhen we find both values are equal or not
( a == b returns 0 )
>Greater thanWe use when we check 'a' Greater than 'b'
( a > b returns 1 )
<Less thanWe use when we check 'a' Less than 'b'
a < b returns 0
!=Not equal toWe use when we check 4 not equal to 3
( 4 != 3 returns 1 )
>=Greater than or equal toWe use when we check 5 Greater than or equal to 3
( 5 >= 3 returns 1 )
<=Less than or equal toWe use when we check 5 Less than or equal to 3
 ( 5 <= 3 return 0 )


Logical Operators :


       &&              AND
        ||        OR
        !       NOT    


AND ( && )

( Age > 18  &&  Age < 50 )

In Logical Operator AND (&&) when Both conditions are true then execute the statement.

OR ( || )

( Age > 18  ||  Age < 50 )

In Logical Operator OR ( || ) when only one or both conditions are true then execute the statement.

NOT ( ! )

( Age > 18  !  Age < 50 )

In Logical Operator NOT ( ! ) first condition must be true and second false then execute the statement.

Conditional Operators :

In Conditional Operator we use ( ? ) and ( :: ) in pair. But how ? see in this line below.

                                        conditional_Expression ? expression1 : expression2

If conditional is true, expression1 is evaluated.
If conditional is false, expression2 is evaluated.

int a=5;
int b=4;
                                             C = ( a > b )? a : b ;

If Conditional_Expression is true then Expression ( a ) will be Evaluate if  Conditional_Expression is 
false then Expression ( b ) will be evaluate.

So, if Expression ( a ) is true then C= 5 else C=4 . Conditional Operator behave same like if else. 

Assignment Operators :

In Program we use Assignment Operator to assign the value in variable or store the result in variable. 

                                                Int a = 100;
Here we used Assignment Operator to assign the value in variable ( a ). Assignment Operator assign the right side value in left side.

Increment And Decrement Operators :

Increment And Decrement Operator simply increase or decrease the value. We can use this Operator by two ways Pre Increment And Decrement and Post Increment And Decrement Operator.
                                                                    Int a = 10;

If we use Increment Operator ( a++ ) then a = 10 and if we use Decrement Operator ( a-- ) then a = 9.

Pre    ++a , --a
Post  a++,  a--


                                          int a =100, b;


Post Increment :

b = a++;  In this Expression first value of ( a ) assign to ( b ) then Increment Operator apply

so a = 101 and b = 100

Pre Increment :

b = ++ a ; In this Expression first Increse the value of ( a ) then assign the value in ( b )

so in this case a= 101 and b= 101.

Bitwise Operators :

        &               AND
        ||         OR
        ^   Exclusive  OR       
        <<        left shift
        >>       right shift   

All through computation, mathematical operations like: addition, subtraction, addition and division are converted to bit-stage which makes processing quicker and saves strength. Bitwise operators are used in C programming to perform bit-level operations.

Special Operators :

Sizeof operator tells how much memory occupy this operand it shows in Byte.

int a = 100;

c= Sizeof (a);

So Sizeof operator return 2 because ( a ) has Integer data types And Integer takes 2 Bytes in memory. We can use Sizeof Operator for finding the size of Array Structure etc.




Friday, 24 March 2017

Constants And Variables

Variables is a location where values are store.When we make our program we use data types for storing different types of values in our program and variable uses for handling the values.

                                                             Int a = 9;

Int is a data type and (a) is variable name and 9 is the value which store in variable (a).When we need to use 9 in our program than we use a instead of 9.

What is the difference between a constant and a variable?

The difference between variables and constants is that value of variables may can change during the execution of program at any time but constants can never change their value.Constants can be very useful, Pi for instance is a good example to declare as a constant.

Thursday, 23 March 2017

C data types

In C language we make variables by using data types.If we need to store value from user so for that purpose we need to store vale in memory space for that reason we make variables. It is mean that variables are the particular location in memory space where our values store.

let's see how we make variables by using Data Types.

                           data_type variable_name ;
                         
                              int   a ;

Here ( a ) is a variable name which create in memory now we can store any integer type of vale in this variable. Int is a C datatypes it shows only integer types of value will be store in this variable.

Data types is a keyword which define which type of value will be store. Here are some basic Data Types in C :

data types are further divided into Two parts.

  • Primary Data Types 
  • Secondary Data Types 

Primary Data Types 


Integer
Char
Float
Double
Void

Secondary Data Types

Array
Pointer 
structure 
Enum 






Wednesday, 22 March 2017

C Programming Structures

What is structure in c programming?

Structure is the most frequently used Custom data type. When we want to work with different variables of different data types(i.e int, char ,float) for a particular task then we need to use structure.

C Programming Struct :

We declare custom data type by using the keyword Struct. Struct defines a physically list of grouped variables to be placed under one name in a block of memory.

Tuesday, 21 March 2017

C Header File

Header file is a file with extension ".h" which contains C Function definitions and declarations and to be shared between several source files.

Prototype of printf and scanf are define in stdio.h. When we call printf or scanf first call go to stdio.h and stdio.h take the original definition from library and load it.

There are two types of header files user defined and system defined we can include both by using preprocessing directive #inclde.

System Define Header File :

System header file c it is mean that all files are already stored in standard list of directories.To include in-constructed header report we use triangular bracket.

#include <fileName>  

User Define Header File :

User header files c it is mean that we can make our own header files and use it when need it. We can include it by using this syntax.

#include "fileName"  




what is a preprocessor || preprocessor directives

what is a preprocessor :

Preprocessor is a program which runs before the compilation. Preprocessor is not a part of compiler but it is a step executed before the source code is compiled. All preprocessor command start with a symbol of (#).# is called Preprocessor directive and the word after # is called Preprocessor command.

preprocessor directives :

Preprocessor directives are traces covered in a application that being with the person #, which cause them to different from an ordinary source code text. They are invoked through the compiler to process a few programs before compilation. Preprocessor directives trade the text of the supply code and the end result is a brand new source code with out those directives.



Sunday, 19 March 2017

C programming Introduction || History of C Lanuage

Introduction To C Programming 




Dennis M. Ritchie is the person who invented the C language at the Bell Telephone Laboratories in 1972. C is a computer programming General Purpose Language and the most extensively used Computer Language.

Initially Ken Thompson and after that Dennis Ritchie developed B Programming Language in 1969 and after that in 1972 B Programming Language apparent as a C Programming Language.


C is a high-level and general purpose programming language that is ideal for developing firmware or portable applications. Originally intended for writing system software.


The Unix operating system and nearly all Unix applications are written in the C language. C has now become a largely used professional language for different reasons. Some reasons are listed below :


  • Structured Language.
  • Easy To Learn .
  • C Produces Efficient Program.
  • It can handle Low-Level Activities.
  • It can be compiled on the different type of computer.

Features Of C Language 

C Programming Language has one of the most powerful Features on it. Some Features are listed below : 

Portability :

C Programming Language is really Portable it's means that once a program write down in C language it can be run on another machine with little or no modification.

Low-Level Features :

C language provides Low-Level Features that is generally provided by lower level languages.
Assembly Language is a lower level language and C language is nearly interconnected to assembly language.

High Level Features :

The C compiler combines the ability of an assembly language with features of a high-level language. Now it is becomes more user friendly as compare to previous programming language such as BCPL ( Basic Combined Programming Language ), Pascal and other languages never give such a great feature to manage Data.

Powerful Language :

C Programming code runs nearly as fast as assembly language code. It is help to reduce the loading time of any program which is written in C language.

C code give access to low level assembly code instantly using inline assembler.
It provides comprehensive range of Data Types.Provides comprehensive range of Functions.
C uses less memory.

Uses Of Pointers :

C Pointers have right to access memory directly and support efficient use of Pointers.